programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Changing String Value (if and else statements

Al Jensen
Greenhorn
Posts: 1
This is the assigment. I believe I am only allowed to use If and else statements

> The following algorith yields the season (Spring, Summer, Fall, or
> Winter) for a given month of the day.
>
> IF month is 1,2, or 3, season = "Winter
> Else if month is 4, 5, or 6, season = "Spring"
> Else if month is 7,8, 9, season = "Summer"
> Else if month is 10,11, or 12, season = "Fall"
> If month is divisible by 3 and day >= 21
> If season is "Winter", season = "Summer"
> Else if season is "Spring", season = "Spring"
> Else if season is "Summer", season = "Fall"
> Else season = "Winter"
>
> Write a program that prompts the user for a month and day and then
> prints the season, as determined by this algorithm

Heres what I got so far. I can't get the last part to get the seasons to change if the month is divisible by 3 and day is above 20.

Manoj Kumar Jain
Ranch Hand
Posts: 198
for the part that you didn't get is simple, you just need to check for all 3 conditions Month, day and season.

you can use nested if else in that condition just check for the month and day. then if season=x make it y, if season=p make it q like that..

Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Welcome to the Ranch.

It seems you're almost finished with this. You just have to remove the System.out.println statements on lines 18, 22, 28 and 33 and print the value of the variable season at the end of the program instead (after line 53). Right now you are printing the value before the last part (lines 37-52) has executed, so obviously you don't see the result of the logic in that last part.

It also looks like you forgot something at line 39, there's an empty if-block there.

 Don't get me started about those stupid light bulbs.