Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class kap4_opg3{
  4.    public static void main(String[] args){
  5.       Scanner console = new Scanner(System.in);
  6.       System.out.print("Write a date like this \"27/7\" for 27th of July: ");
  7.      
  8.       String date = console.next();
  9.      
  10.      
  11.       System.out.println("You wrote: "+date);
  12.       System.out.println("Which is "+season(date));
  13.      
  14.    }
  15.    
  16.    public static String season(String dateAndMonth){
  17.       String[] dates = dateAndMonth.split("/");
  18.      
  19.       int date = Integer.parseInt(dates[0]); // converts the date into an integer
  20.       int month = Integer.parseInt(dates[1]); // converts the month into an integer
  21.      
  22.       int day = 0;
  23.      
  24.       switch(month){
  25.          case 1:
  26.             day = date;
  27.             break;
  28.          case 2:
  29.             day = 31+date; // there are 31 days in January.
  30.             break;
  31.          case 3:
  32.             day = 59+date; // there are 28 days in February.
  33.             break;
  34.          case 4:
  35.             day = 90+date; // there are 31 days in March.
  36.             break;
  37.          case 5:
  38.             day = 120+date; // there are 30 days in April.
  39.             break;
  40.          case 6:
  41.             day = 151+date; // there are 31 days in May
  42.             break;
  43.          case 7:
  44.             day = 181+date; // there are 30 days in June
  45.             break;
  46.          case 8:
  47.             day = 212+date; // 31 in July
  48.             break;
  49.          case 9:
  50.             day = 243+date; // 31 in August
  51.             break;
  52.          case 10:
  53.             day = 273+date; // 30 in September
  54.             break;
  55.          case 11:
  56.             day = 304+date; //31 in October
  57.             break;
  58.          case 12:
  59.             day = 334+date; // 30 in November
  60.             break;
  61.       }
  62.      
  63.       String season = "";
  64.        
  65.       if(day<=74||day>=350){  // 74 = 15/3 and 350 = 16/12
  66.          season = "Winter";
  67.       }else if(day>=75&&day<=166){ // 75 = 16/3 and 166 = 15/5
  68.          season = "Spring";
  69.       }else if(day>=167&&day<=258){ // 167 = 16/5 and 258 = 15/9
  70.          season = "Summer";
  71.       }else if(day>=259&&day<=349){ // 259 = 16/9 and 349 = 15/12
  72.          season = "Fall";
  73.       }
  74.      
  75.       return season;
  76.    }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement