aspose file tools*
The moose likes Beginning Java and the fly likes Method explicit params are doubles, can return string? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Method explicit params are doubles, can return string?" Watch "Method explicit params are doubles, can return string?" New topic
Author

Method explicit params are doubles, can return string?

Kimberly Ivens
Greenhorn

Joined: Nov 08, 2012
Posts: 9
I am a beginning Java student and am studying IF statements.
Please see the following Season class and SeasonTester. I do not know how to make the return in the method
in Season class work when using the tester. It will not print out which season it is.
Please help. I'm sure this is a very simple question for the Java experts here.


__________________________________________________________

The output I get asks for the low temp and then the high temp, and then the program stops.
How can I get it to print out the probable season?

Thank you!
Kimberly

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

You do return a String value from the method, but you don't do anything with it. You should assign the value returned from the method to a String variable, then you probably want to display it, which means printing it out to System.out.


Steve
Kimberly Ivens
Greenhorn

Joined: Nov 08, 2012
Posts: 9
SteveLuke -- Yes, thank you. I can't believe it was that simple and I missed it. I added a variable for the method call.

Another question: I cannot get the program to differentiate between Spring and Fall due to the IF statements in this
block of code:



How can I make the ELSE IF return Fall value correctly?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Kimberly Ivens wrote:SteveLuke -- Yes, thank you. I can't believe it was that simple and I missed it. I added a variable for the method call.

Another question: I cannot get the program to differentiate between Spring and Fall due to the IF statements in this
block of code:



How can I make the ELSE IF return Fall value correctly?


Pretend you're the computer. Manually work through the above code, step by step, if the temp is 65.

See the problem?

If that doesn't help, add print statements to both of those if blocks, so that you can see when you're entering them, and what the temp is.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11230
    
  16

Another way to think of it...forget about java, programming, and computers.

I tell you "The temp is 60 degrees".

How can you figure out if it is probably fall or spring?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Kimberly Ivens
Greenhorn

Joined: Nov 08, 2012
Posts: 9
The only way I can figure out how to make FALL come up is to put it's IF ELSE statement above Spring's statement so that if the temp
is 60 degrees, then it sees Fall first. When the higher temp is entered as above 70, then it will find Spring. Is that right?
(Other than just having the output say "open a window to find the season"....)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Kimberly Ivens wrote:The only way I can figure out how to make FALL come up is to put it's IF ELSE statement above Spring's statement so that if the temp
is 60 degrees, then it sees Fall first. When the higher temp is entered as above 70, then it will find Spring. Is that right?
(Other than just having the output say "open a window to find the season"....)


Yup, switching the order would be the way to go. If you think about it, it makes perfect sense. If it's < 70, then it's definitely going to be < 80, so the way you have it now, if the second one (< 70) is true, then the first one (< 80) must also be true, so you'll never get a chance to get to the second one.

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11230
    
  16

Kimberly Ivens wrote:The only way I can figure out how to make FALL come up is to put it's IF ELSE statement above Spring's statement so that if the temp
is 60 degrees, then it sees Fall first.

that's not what I meant. Forget about java. forget about IF-ELSE statements. forget about computers.

I am asking YOU to use your brain. I say "The temp. is 50 degrees. What season is it?"

Now, it is probably not summer, as summers are hot and almost always above 50 degrees.
It is also probably not winter, as winters are cold and almost always below 50 degrees.

But how can you tell if it is Spring or Fall? Both of them have cool temperatures. 50 is a reasonable temp for either.

I think if you reverse the order of your statements, you will still run into issues when it is Spring and between 40 and 70...you will hit your "fall" logic first and declare it to be false.

You don't have enough info to determine fall or spring just off the temperature.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Method explicit params are doubles, can return string?