Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package seasonclassification;
- import java.util.Scanner;
- /**
- *
- * @author udx14wfu
- */
- public class SeasonClassification {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner input = new Scanner(System.in);
- int month, day;
- System.out.println("Enter a month: ");
- month = input.nextInt();
- System.out.println("Enter a day: ");
- day = input.nextInt();
- if(isValidDate(month, day)==true){
- System.out.println(findSeason(month,day));
- }else{
- System.out.println("Sorry, but the date is not valid!");
- }
- }
- public static boolean isValidDate(int month, int day){
- int[] daysCount = new int[]{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- boolean valid = false;
- if(month>=1 && month <=12){
- if((month>=1 && month<=12) && (day>=1 && day<=daysCount[month-1])){
- valid = true;
- }
- }else{
- valid = false;
- }
- return valid;
- }
- public static String findSeason(int month, int day){
- String season = null, mth = null;
- switch(month){
- case 1: mth = "January";
- break;
- case 2: mth = "February";
- break;
- case 3: mth = "March";
- break;
- case 4: mth = "April";
- break;
- case 5: mth = "May";
- break;
- case 6: mth = "June";
- break;
- case 7: mth = "July";
- break;
- case 8: mth = "August";
- break;
- case 9: mth = "September";
- break;
- case 10:mth = "October";
- break;
- case 11:mth = "November";
- break;
- case 12:mth = "December";
- break;
- }
- if(mth=="December" && day>=21){
- season = "Winter";
- }else if(mth=="December" && day<21){
- season = "Autumn";
- }else if(mth=="January"){
- season = "Winter";
- }else if(mth=="February"){
- season = "Winter";
- }else if(mth=="March" && day<=20){
- season = "Winter";
- }else if(mth=="March" && day>=21){
- season = "Spring";
- }else if(mth=="April"){
- season = "Spring";
- }else if(mth=="May"){
- season = "Spring";
- }else if(mth=="June" && day<=20){
- season = "Spring";
- }else if(mth=="June" && day>=21){
- season = "Summer";
- }else if(mth=="July"){
- season = "Summer";
- }else if(mth=="August"){
- season = "Summer";
- }else if(mth=="September" && day<=20){
- season = "Summer";
- }else if(mth=="September" && day>=21){
- season = "Autumn";
- }else if(mth=="October"){
- season = "Autumn";
- }else if(mth=="November"){
- season = "Autumn";
- }
- return season;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement