So here's the homework question:
"Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day.
Ex: If the input is:
April 11 the output is:
Spring In addition, check if the string and int are valid (an actual month and day).
Ex: If the input is:
Blue 65 the output is:
Invalid "
My code is as follows:
'''
String inputMonth;
int inputDay;
inputMonth = scnr.next();
inputDay = scnr.nextInt();
if( ((inputMonth == "March") || (inputMonth == "march")) && ((inputDay >= 20) && (inputDay <= 31))){
System.out.println("Spring");
}
else if( ((inputMonth == "April") || (inputMonth == "april")) && ((inputDay >= 1) && (inputDay <= 30))){
System.out.println("Spring");
}
else if( ((inputMonth == "May") || (inputMonth == "may")) && ((inputDay >= 1) && (inputDay <= 31))){
System.out.println("Spring");
}
else if( ((inputMonth == "June") || (inputMonth == "june")) && ((inputDay >= 1) && (inputDay <= 20))){
System.out.println("Spring");
}
else if( ((inputMonth == "June") || (inputMonth == "june")) && ((inputDay >= 21) && (inputDay <= 30))){
System.out.println("Summer");
}
else if( ((inputMonth == "July") || (inputMonth == "july")) && ((inputDay >= 1) && (inputDay <= 31))){
System.out.println("Summer");
}
else if( ((inputMonth == "August") || (inputMonth == "august")) && ((inputDay >= 1) && (inputDay <= 31))){
System.out.println("Summer");
}
else if( ((inputMonth == "September") || (inputMonth == "september")) && ((inputDay >= 1) && (inputDay <= 21))){
System.out.println("Summer");
}
else if( ((inputMonth == "September") || (inputMonth == "september")) && ((inputDay >= 22) && (inputDay <= 30))){
System.out.println("Autumn");
}
else if( ((inputMonth == "October") || (inputMonth == "october")) && ((inputDay >= 1) && (inputDay <= 31))){
System.out.println("Autumn");
}
else if( ((inputMonth == "November") || (inputMonth == "november")) && ((inputDay >= 22) && (inputDay <= 30))){
System.out.println("Autumn");
}
else if( ((inputMonth == "December") || (inputMonth == "december")) && ((inputDay >= 1) && (inputDay <= 20))){
System.out.println("Autumn");
}
else if( ((inputMonth == "December") || (inputMonth == "december")) && ((inputDay >= 21) && (inputDay <= 31))){
System.out.println("Winter");
}
else if( ((inputMonth == "January") || (inputMonth == "january")) && ((inputDay >= 1) && (inputDay <= 31))){
System.out.println("Winter");
}
else if( ((inputMonth == "February") || (inputMonth == "february")) && ((inputDay >= 1) && (inputDay <= 29))){
System.out.println("Winter");
}
else if( ((inputMonth == "March") || (inputMonth == "march")) && ((inputDay >= 1) && (inputDay <= 19))){
System.out.println("Winter");
}
else{
System.out.println("Invalid");
}
'''
I believe the problem is that it wont read both the string and the integer correctly but I'm not exactly sure why.
Also I know there's probably a shorter way to do this but I don't know how yet, if anyone would like to help me with that too it would be infinitely appreciated.
Thank you in advance