import ohjava.*; public class TestDate { public static void main(String args[]) { System.out.println("Please give me a valid date."); SimpleIO.prompt("Enter day(< 31) : "); int d = Integer.parseInt(SimpleIO.readLine()); SimpleIO.prompt("Enter month(< 12): "); int m = Integer.parseInt(SimpleIO.readLine()); SimpleIO.prompt("Enter year(> 0) : "); int y = Integer.parseInt(SimpleIO.readLine()); Date day = new Date(m,d,y); System.out.println("\nThe date you entered is " + day); for (;;) { printMenu(); SimpleIO.prompt("Enter your option: "); String option = SimpleIO.readLine().toLowerCase(); if (option.equals("a")) { SimpleIO.prompt("Enter number of days to add to the date: "); int n = Integer.parseInt(SimpleIO.readLine()); System.out.println("\nThe date obtained after adding " + n + " to " + day + " is " + day.add(n)); } else if (option.equals("s")) { SimpleIO.prompt("Enter number of days to subtract from the date: "); int n = Integer.parseInt(SimpleIO.readLine()); System.out.println("\nThe date obtained after subtracting " + n + " from " + day + " is " + day.sub(n)); } else if (option.equals("y")) { System.out.println("\nThe date previous to " + day + " is " + day.previousDay()); } else if (option.equals("t")) { System.out.println("\nThe date after " + day + " is " + day.nextDay()); } else if (option.equals("n")) { System.out.println("\nThe first day of the next month for " + day + " is " + day.firstOfNextMonth()); } else if (option.equals("p")) { System.out.println("\nThe first day of the previous month for " + day + " is " + day.firstOfPreviousMonth()); } else if (option.equals("b")) { System.out.println("Please give me another valid date."); SimpleIO.prompt("Enter day(< 31) : "); int d2 = Integer.parseInt(SimpleIO.readLine()); SimpleIO.prompt("Enter month(< 12): "); int m2 = Integer.parseInt(SimpleIO.readLine()); SimpleIO.prompt("Enter year(> 0) : "); int y2 = Integer.parseInt(SimpleIO.readLine()); Date day2 = new Date(m2,d2,y2); System.out.println("\nThe number of days between " + day + " and " + day2 + " is " + day.daysBetween(day2)); } else if (option.equals("c")) { System.out.println("Please give me another valid date."); SimpleIO.prompt("Enter day(< 31) : "); int d3 = Integer.parseInt(SimpleIO.readLine()); SimpleIO.prompt("Enter month(< 12): "); int m3 = Integer.parseInt(SimpleIO.readLine()); SimpleIO.prompt("Enter year(> 0) : "); int y3 = Integer.parseInt(SimpleIO.readLine()); Date day3 = new Date(m3,d3,y3); if (day.before(day3)) System.out.println("\n" + day + " is before " + day3); else if (day.after(day3)) System.out.println("\n" + day + " is after " + day3); else System.out.println("\n" + day + " is same as " + day3); } else if (option.equals("q")) { break; } } } private static void printMenu() { System.out.println("\n Welcome to Date Tester\n"); System.out.println("(a) Add number to the date. "); System.out.println("(s) Subtract number from date. "); System.out.println("(y) Yesterday. "); System.out.println("(t) Tomorrow. "); System.out.println("(n) First of next month. "); System.out.println("(p) First of previous month. "); System.out.println("(b) Days between. "); System.out.println("(c) Compare Dates to see if one is before another. "); System.out.println("(q) Quit. "); System.out.println(); } }