aspose file tools*
The moose likes Beginning Java and the fly likes What is retuned, what am i checking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is retuned, what am i checking" Watch "What is retuned, what am i checking" New topic
Author

What is retuned, what am i checking

Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
Hi,

I have to work on code that someone else has written, but not finished.

In the code ( a .JSP page) the following method is called

if (localiser.isUSA()))
do this;
else
do that;

The class localiser, does not have a method for isUSA(), so i have to write it. My question is what is being returned, or how does this check work as nothing is being passed in, so i dont know what to pass out.

I am at a muddle.

Thanks
Roger
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, if you want to use the output of that method in a conditional statement its going to have to have a boolean return value.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
Ok thanks

i figured it was a boolean, but i dont know how to implement or how to use it. I have looked at the API and for it to work i obviously have to check something.

would the method go something like this?

public boolean isUSA(){
if(lang.equals("en"))
return true;
}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

How you implement this is up to you. I'd speak to whoever is setting the requirements. You'll need to find out what the check actually means, i.e. what set of circumstances need to be met for "isUSA" to be true.
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
paul

The check is as i wrote in the previous post.
It is classified as USA if the language is english, thats it.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If that's the case, I think you may have answered your own question (though your compiler will complain if you implement your method exactly as you suggest).
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It's fairly common to see:

Those of us who consider ourselves very clever and good looking like to shorten this a bit. Can you do it in one line?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
Like this, Maybe?



This should do the trick (i think)
Michael Valentino
Ranch Hand

Joined: Nov 01, 2005
Posts: 96
I was thinking more along the lines of:



or something of the like
[ May 30, 2006: Message edited by: Michael Valentino ]

SCJP 1.4, SCWCD J2EE 1.4, SCJD J2SE 1.5, SCBCD J2EE 1.3, SCDJWS (In Progress)
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
Does that mean that i am returning a String?

I tried to implement it the way you suggested but i got a complier error.

I am passing in the string in the mehod header, as in boolean isUSA(String lang)

My original question was what am i actually sending back to the calling method
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

No! The statement:

You are calling the method equalsIgnoreCase of class String here. That method returns a boolean.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
I'm going to chime in for all our friends over seas. Just because the language is english doesn't make it a USA location. Locales contain two parts, iso language code and iso country code. You need to test the country code portion to determine if the location is usa


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
Ok

I am still getting a compiler error.

the JSP page is giving out about the localiser calling the method, isUSA();

its called like this :

The actual method in the Localiser class is :



Trying to simplify here, just to get the boolean working, will make it proper for international users then.
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
CORRECTION TO LAST POST

the code should read


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42283
    
  64
And the USA -being a free country- allows you to install a Japanese JDK, or to set your computer to a timezone in South Africa, or to set the default language to German, all of which might result in the test not working the way you envision it


Ping & DNS - my free Android networking tools app
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3673
    
  15
Originally posted by Roger Waters:
CORRECTION TO LAST POST

the code should read




isUsa expects a String argument to be passed to it. You're not passing any argument.


Joanne
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
ok

Would someone be kind enough to show me how they would implement it, in both the class and the calling page.

I feel like i have started an issue on localisation, when all i wanted to do was get a boolean method to work.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61431
    
  67

What part of Joanne's post did you not understand?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Ulf Dittmer:
And the USA -being a free country- allows you to install a Japanese JDK, or to set your computer to a timezone in South Africa, or to set the default language to German, all of which might result in the test not working the way you envision it


�Qui�n dice que un Americano no puede hablar Espa�ol?


There is no emoticon for what I am feeling!
Roger Waters
Greenhorn

Joined: May 10, 2006
Posts: 14
Joanne Thank you. your suggestion fixed my problem.

Bear, Thanks also. In haste i had not read joannes post. I thought it was mine.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
To be fair, Joanne's post was nearly simultaneous with yours. It's easy to miss in a case like that.

Incidentally, I have heard rumors (or were they rumours?) that some people may speak English outside the USA. Which seems an even more likely reason the result of this method may be incorrect.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is retuned, what am i checking