import java.io.*; class SimplePersonMenu { private BufferedReader br; public SimplePersonMenu() { br = new BufferedReader (new InputStreamReader (System.in)); } public void display() { System.out.println (".....Menu....."); System.out.println ("1. Create a person"); System.out.println ("2. Display the person"); System.out.println ("3. Display the person's name"); System.out.println ("4. Display the person's id number"); System.out.println ("5. Set the person's id number"); System.out.println ("6. Exit"); } public int getSelection() throws IOException, NumberFormatException, SimplePersonMenuException { System.out.println (""); System.out.print ("Enter your choice: "); int selection = Integer.parseInt (br.readLine()); if ( (selection < 1) || (selection > 6) ) throw new SimplePersonMenuException ("Selection, " + selection + " wasn't between 1 and 6, inclusive."); return selection; } public SimplePerson createPerson() throws SimplePersonMenuException { try { System.out.print ("Please enter the person's name: "); String name = br.readLine(); System.out.print ("Please enter the person's id number: "); int idNumber = Integer.parseInt (br.readLine()); return new SimplePerson (name, idNumber); } catch (NumberFormatException ioe) { throw new SimplePersonMenuException ("Can't create a simple person because the student number wasn't an integer."); } catch (IOException ioe) { throw new SimplePersonMenuException ("Can't set the idNumber, because of keyboard input problems."); } } public void changeID (SimplePerson p) throws SimplePersonMenuException{ try { System.out.print ("Please enter the person's id number: "); int idNumber = Integer.parseInt (br.readLine()); p.setId (idNumber); } catch (NumberFormatException nfe) { throw new SimplePersonMenuException ("Can't change the id number, because ti needs to eb an integer."); } catch (IOException ioe) { throw new SimplePersonMenuException ("Can't create a simple person because of keyboard inut problems."); } } public static void main (String[] args) { SimplePerson p = null; int selection = -1; while (selection != 6) { try { SimplePersonMenu menu = new SimplePersonMenu(); menu.display(); selection = menu.getSelection(); if (selection == 1) { p = menu.createPerson(); } if (selection == 2) { // Display the person System.out.println (p); } if (selection == 3) { // Display the person's name System.out.println (p.getName()); } if (selection == 4) { // Display the person's id number System.out.println (p.getIdNumber()); } if (selection == 5) { // Change the person's id number menu.changeID(p); } } catch (IOException ioe) { System.out.println ("Shit. Fuck. Damn. Can't read from the keyboard."); } catch (NumberFormatException nfe) { System.out.println ("You didn't enter a number, so we're dead. Fuck!"); } catch (SimplePersonMenuException spme) { System.out.println (spme); } } } }