Advertisement
RnD

SeasonClassification - UEA CMP

RnD
Oct 17th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package seasonclassification;
  8. import java.util.Scanner;
  9.  
  10. /**
  11.  *
  12.  * @author udx14wfu
  13.  */
  14. public class SeasonClassification {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args) {
  20.         // TODO code application logic here
  21.         Scanner input = new Scanner(System.in);
  22.         int month, day;
  23.        
  24.         System.out.println("Enter a month: ");
  25.         month = input.nextInt();
  26.         System.out.println("Enter a day: ");
  27.         day = input.nextInt();
  28.        
  29.         if(isValidDate(month, day)==true){
  30.             System.out.println(findSeason(month,day));
  31.         }else{
  32.             System.out.println("Sorry, but the date is not valid!");
  33.         }
  34.     }
  35.    
  36.     public static boolean isValidDate(int month, int day){
  37.         int[] daysCount = new int[]{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  38.         boolean valid = false;
  39.        
  40.        if(month>=1 && month <=12){
  41.            if((month>=1 && month<=12) && (day>=1 && day<=daysCount[month-1])){
  42.                valid = true;
  43.            }
  44.        }else{
  45.            valid = false;
  46.        }
  47.        
  48.        return valid;
  49.     }
  50.    
  51.     public static String findSeason(int month, int day){
  52.         String season = null, mth = null;
  53.        
  54.         switch(month){
  55.             case 1: mth = "January";
  56.                 break;
  57.             case 2: mth = "February";
  58.                 break;
  59.             case 3: mth = "March";
  60.                 break;
  61.             case 4: mth = "April";
  62.                 break;
  63.             case 5: mth = "May";
  64.                 break;
  65.             case 6: mth = "June";
  66.                 break;
  67.             case 7: mth = "July";
  68.                 break;
  69.             case 8: mth = "August";
  70.                 break;
  71.             case 9: mth = "September";
  72.                 break;
  73.             case 10:mth = "October";
  74.                 break;
  75.             case 11:mth = "November";
  76.                 break;
  77.             case 12:mth = "December";
  78.                 break;
  79.             }
  80.        
  81.         if(mth=="December" && day>=21){
  82.             season = "Winter";
  83.         }else if(mth=="December" && day<21){
  84.             season = "Autumn";
  85.         }else if(mth=="January"){
  86.             season = "Winter";
  87.         }else if(mth=="February"){
  88.             season = "Winter";
  89.         }else if(mth=="March" && day<=20){
  90.             season = "Winter";
  91.         }else if(mth=="March" && day>=21){
  92.             season = "Spring";
  93.         }else if(mth=="April"){
  94.             season = "Spring";
  95.         }else if(mth=="May"){
  96.             season = "Spring";
  97.         }else if(mth=="June" && day<=20){
  98.             season = "Spring";
  99.         }else if(mth=="June" && day>=21){
  100.             season = "Summer";
  101.         }else if(mth=="July"){
  102.             season = "Summer";
  103.         }else if(mth=="August"){
  104.             season = "Summer";
  105.         }else if(mth=="September" && day<=20){
  106.             season = "Summer";
  107.         }else if(mth=="September" && day>=21){
  108.             season = "Autumn";
  109.         }else if(mth=="October"){
  110.             season = "Autumn";
  111.         }else if(mth=="November"){
  112.             season = "Autumn";
  113.         }
  114.        
  115.         return season;
  116.     }
  117.    
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement