Skip to content

Instantly share code, notes, and snippets.

@Angel-Rojas
Last active June 8, 2017 01:18
Show Gist options
  • Save Angel-Rojas/622137fcd4ee94bbeae6 to your computer and use it in GitHub Desktop.
Save Angel-Rojas/622137fcd4ee94bbeae6 to your computer and use it in GitHub Desktop.
Seasons, it takes in user input and then decides what "Season" your specified date lands on. *still needs some work*
/*
* This program prints the seasons
*
* @author Angel Rojas
* Course: COMP B11
* Created: Sep 25, 2014
* Source File: Seasons.java
*/
import java.util.Scanner;
public class Seasons {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); // set up our Input take-in Scanner.
String season = "Your unchanged season."; // Edit: This will print if invalid # is passed.
// user enters month and day
System.out.println("Please enter Month followed by Day");
int month = in.nextInt();
int day = in.nextInt();
// checks month and day!
if (month <= 3) {
season = "Winter";
} else if (month == 4 || month == 5 || month == 6) {
season = "Spring";
} else if (month == 7 || month == 8 || month == 9) {
season = "Summer";
} else if (month == 10 || month == 11 || month == 12) {
season = "Fall";
}
if (month % 3 == 0 && day >= 21) {
if (season.equals("Winter")) {
season = "Spring";
} else if (season.equals("Spring")) {
season = "Summer";
} else if (season.equals("Summer")) {
season = "Fall";
} else
season = "Winter";
}
System.out.print(season);
in.close(); // close out our Input reader
}
}
@ChadH1971
Copy link

I see you have String Winter, String Spring, String Summer, String Fall, but these are never used anywhere else in your code. They have not been initialized, so the compiler is going to scream about that and they also violate the java variable naming convention.
Here is my code for the same project if you want to compare
https://gist.github.com/690d17d52c2a2181bee5.git

@pathawks
Copy link

pathawks commented Nov 9, 2015

@ChadH1971
Copy link

Thanks Pat. What did I do wrong? I used the copy url button, but it didn't paste correctly. Should I have used the embed url button?

@Angel-Rojas
Copy link
Author

Oh, you're right! Can't believe i had initialized those and never even used them. MMk thanks for the input guys! Making said changes now.
So why does our String season have to be set to a blank "" str? can you guys maybe explain that. Thanks again (: EDIT: Code is running smoothly :) so much better than when i originally wrote this back in 2014 aha. Thanks guys for all the help, much appreciated!

@pathawks
Copy link

pathawks commented Nov 9, 2015

@ChadH1971 You used the clone URL, which is what you would use if you wanted to copy the Gist to your computer using a Git client. To share the page, just copy the URL from your browser like you would for any other webpage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment