import java.io.*; class CalendarChange3 { public static void main(String[] args) throws IOException { int d,m,y; int change; String command; char ch; Calendar3 calendar; BufferedReader in = Text.open(System.in); for(;;) try { System.out.print("Enter day: "); d=Text.readInt(in); System.out.print("Enter month: "); m=Text.readInt(in); System.out.print("Enter year: "); y=Text.readInt(in); calendar = new Calendar3(d,m,y); break; } catch(DateException e) { System.out.println("Invalid date "+e.getMessage()); } calendar.display(); System.out.println("Enter + to add a day, - to subtract a day"); System.out.println("followed by a number for multiple days"); System.out.println("Or enter q to quit"); do { System.out.print("> "); command=Text.readString(in); ch=command.charAt(0); change=0; if(ch=='+') change=1; else if(ch=='-') change=-1; else if(ch!='q') System.out.println("Invalid command"); if(change!=0) if(command.length()==1) calendar.addDay(change); else try { change*=Integer.parseInt(command.substring(1)); calendar.addDay(change); } catch(NumberFormatException e) { System.out.println("Invalid command"); } calendar.display(); } while(ch!='q'); System.exit(0); } }