/* This program has menu options to manipulate a personal planner, including: add a Task, DueDo, or Appointment to the planner (getting input from the user), as well as search for items, and display all items. It adds exception handling to the week12.java file. */ import java.io.*; import java.util.*; public class week13 { private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { int choice = 1; Planner p = new Planner(); Task t; DueDo d; Appointment a; String s; while (choice != 0) { choice = menu(); switch (choice) { case 0: break; case 1: t = new Task(); try { t.read(keyboard); p.add(t); } catch (IOException ioe) { System.err.println(ioe); System.err.println("not using entry"); } break; case 2: d = new DueDo(); try { d.read(keyboard); p.add(d); } catch (IOException ioe) { System.err.println(ioe); System.err.println("not using entry"); } break; case 3: a = new Appointment(); try { a.read(keyboard); p.add(a); } catch (IOException ioe) { System.err.println(ioe); System.err.println("not using entry"); } break; case 4: p.display(); break; case 5: System.out.print("what to search for? "); try { s = keyboard.nextLine(); p.search(s); } catch (IOException ioe) { System.err.println(ioe); System.err.println("search cancelled"); } break; default: System.err.println("invalid choice!"); } } } public static int menu() { int choice; System.out.println("0) quit"); System.out.println("1) add to-do item"); System.out.println("2) add due item"); System.out.println("3) add appointment"); System.out.println("4) display items"); System.out.println("5) search"); do { System.out.print(" enter choice -> "); try { choice = keyboard.nextInt(); } catch (InputMismatchException e) { System.err.println(e); choice = -1; } catch (IOException ioe) { System.err.println(ioe); choice = -1; } } while (choice == -1); return choice; } }