/* NextDate.java * Author: Kris og Anne * Translated by: Ida * Exercise 11 for the 4th week * Determines the date of the next day */ import cs1.Keyboard; public class NextDate { public static void main(String[] args) { int daysinmonth=0,day=0,month=0,year=0; // get the year do { System.out.print("Type the year (between 2000 and 2999): "); year = Keyboard.readInt(); } while (year<2000 || year>2999); // get the month do { System.out.print("Type the month: "); month = Keyboard.readInt(); } while (month<1 || month>12); //calculate the number of days in the month switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: daysinmonth=31; break; case 2: { if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )//Leap year!! daysinmonth=29; else daysinmonth=28; } break; default: daysinmonth=30; } //get the day do { System.out.print("Type the day: "); day = Keyboard.readInt(); } while (day<1 || day>daysinmonth); System.out.print("The day after " + day + "/" + month + " " + year + " is "); //determine the date of the next day, and write the result if (day==daysinmonth) { day=1; if (month!=12)//not December month++; else { month=1; year++; } } else day++; System.out.println(day + "/" + month + " " + year); } }