I have seen several examples using switch statements already with cases for 3 months at a time being a different season. But I want to create a method using a switch statement where the seasons start from specific date, for example:
December 21 - March 20 = Winter
March 21 - June 20 = Spring
June 21 - September = Summer
September 21 - December 20 = Autumn
I want to do it using a user-inputted int variable for each the month, and the date.
Please could someone tell me how I could go about doing this? Please bare in mind I am fairly new to coding
My current code includes a method to check if the date is valid but is still a work in progress:
package seasonclassification;
import java.util.Scanner;
public class SeasonClassification {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the month in terms of numbers (e.g March = 3) you wish to check the season of:");
int calMonth = scan.nextInt();
System.out.println("Enter the day in terms of numbers (e.g 27th = 27):");
int calDay = scan.nextInt();
}
public static boolean isValidDate(int month, int day) {
boolean x;
if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12) && (day >= 1) && (day <= 31)) {
x = true;
}
if ((month == 4) || (month == 6) || (month == 9) || (month == 11) && (day >= 1) && (day <= 30)) {
x = true;
}
if ((month == 2) && (day >= 1) && (day <= 29)) {
x = true;
}
else {
x = false;
}
return x;
}
public static String findSeason(int month, int day) {
switch (month,day) {
}
}
}