//NAME: Danish Khan //STUDENT ID: 47324012 //NAME: Adam Su //STUDENT ID: 23628358 // PayrollMenu.java // // ICS H22 Winter 2006 // Lab 3: The Price You Pay // // This class is provided as-is, to give you an example of input using the // new Scanner class in Java 5.0. I expect you to use this class, without // modification, in your program. // // To use this class, first create an object of the class. Whenever you want // to show the menu, call the show() method on it. Whenever you want to ask // the user to choose a command, call the getNextCommand() method, which will // return a PayrollCommand object that represents the user's choice. import java.util.Scanner; public class PayrollMenu { private Scanner scanner; public PayrollMenu(Scanner scanner) { this.scanner = scanner; } public void show() { System.out.println(); System.out.println("Main Menu"); System.out.println("---------"); System.out.println("[A]dd Employee"); System.out.println("[R]emove Employee"); System.out.println("[S]how Employees"); System.out.println("[D]o Weekly Payroll"); System.out.println("[Q]uit"); System.out.println(); } public PayrollCommand getNextCommand() { PayrollCommand command = null; do { //System.out.print("Enter command: "); if (scanner.hasNext() == false) { System.out.println(""); System.out.println("**END OF INPUT FILE**"); System.exit(1); } String s = scanner.nextLine(); if (s.length() > 0) { switch (s.toUpperCase().charAt(0)) { case 'A': command = PayrollCommand.ADD_EMPLOYEE; break; case 'R': command = PayrollCommand.REMOVE_EMPLOYEE; break; case 'S': command = PayrollCommand.SHOW_EMPLOYEES; break; case 'D': command = PayrollCommand.DO_WEEKLY_PAYROLL; break; case 'Q': command = PayrollCommand.QUIT; break; default: System.out.println(" invalid command; try again"); } } } while (command == null); System.out.println(); return command; } }