Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Presents the menu for the user, and awaits input from the user. The menu
- * choice selected by the user is being returned.
- *
- * @return the menu choice by the user as a positive number starting from 1.
- * If 0 is returned, the user has entered a wrong value
- */
- private int showMenu()
- {
- int menuChoice = 0;
- System.out.println("\n***** Property Register Application v0.1 *****\n");
- System.out.println("1. Add property");
- System.out.println("2. List all properties");
- System.out.println("3. Search property");
- System.out.println("4. Calculate average area");
- //TODO: Add more menus
- System.out.println("9. Quit");
- System.out.println("\nPlease enter a number between 1 and 9.\n");
- Scanner sc = new Scanner(System.in);
- if (sc.hasNextInt()) {
- menuChoice = sc.nextInt();
- } else {
- System.out.println("You must enter a number, not text");
- }
- return menuChoice;
- }
- /**
- * Starts the application. This is the main loop of the application,
- * presenting the menu, retrieving the selected menu choice from the user,
- * and executing the selected functionality.
- */
- public void start() {
- boolean finished = false;
- // The while-loop will run as long as the user has not selected
- // to quit the application
- while (!finished) {
- int menuChoice = this.showMenu();
- switch (menuChoice)
- {
- case ADD_PROPERTY:
- //TODO: Fill inn your code here....
- break;
- case LIST_ALL_PROPERTIES:
- //TODO: Fill inn your code here....
- break;
- case FIND_PROPERTY:
- //TODO: Fill inn your code here....
- break;
- case CALCULATE_AVERAGE_AREA:
- //TODO: Fill inn your code here....
- break;
- case EXIT:
- System.out.println("Thank you for using the Properties app!\n");
- finished = true;
- break;
- default:
- System.out.println("Unrecognized menu selected..");
- break;
- }
- }
- }
- ... der følgende konstanter er definert:
- // Constants representing the different menu choices
- private final int ADD_PROPERTY = 1;
- private final int LIST_ALL_PROPERTIES = 2;
- private final int FIND_PROPERTY = 3;
- private final int CALCULATE_AVERAGE_AREA = 4;
- private final int EXIT = 9;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement