Advertisement
Guest User

Oppgave 4

a guest
Nov 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1.     /**
  2.      * Presents the menu for the user, and awaits input from the user. The menu
  3.      * choice selected by the user is being returned.
  4.      *
  5.      * @return the menu choice by the user as a positive number starting from 1.
  6.      *                 If 0 is returned, the user has entered a wrong value
  7.      */
  8.     private int showMenu()
  9.  
  10.     {
  11.         int menuChoice = 0;
  12.  
  13.         System.out.println("\n***** Property Register Application v0.1 *****\n");
  14.         System.out.println("1. Add property");
  15.         System.out.println("2. List all properties");
  16.         System.out.println("3. Search property");
  17.         System.out.println("4. Calculate average area");
  18.         //TODO: Add more menus
  19.         System.out.println("9. Quit");
  20.         System.out.println("\nPlease enter a number between 1 and 9.\n");
  21.         Scanner sc = new Scanner(System.in);
  22.  
  23.         if (sc.hasNextInt()) {
  24.             menuChoice = sc.nextInt();
  25.         } else {
  26.             System.out.println("You must enter a number, not text");
  27.         }
  28.         return menuChoice;
  29.     }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.    
  36.  
  37.     /**
  38.      * Starts the application. This is the main loop of the application,
  39.      * presenting the menu, retrieving the selected menu choice from the user,
  40.      * and executing the selected functionality.
  41.      */
  42.     public void start() {
  43.         boolean finished = false;
  44.  
  45.         // The while-loop will run as long as the user has not selected
  46.         // to quit the application
  47.         while (!finished) {
  48.             int menuChoice = this.showMenu();
  49.             switch (menuChoice)
  50.             {
  51.                 case ADD_PROPERTY:
  52.                     //TODO: Fill inn your code here....
  53.                     break;
  54.                    
  55.                 case LIST_ALL_PROPERTIES:
  56.                     //TODO: Fill inn your code here....
  57.                     break;
  58.                    
  59.                 case FIND_PROPERTY:
  60.                     //TODO: Fill inn your code here....
  61.                     break;
  62.                    
  63.                 case CALCULATE_AVERAGE_AREA:
  64.                     //TODO: Fill inn your code here....
  65.                     break;
  66.                    
  67.                 case EXIT:
  68.                     System.out.println("Thank you for using the Properties app!\n");
  69.                     finished = true;
  70.                     break;
  71.                    
  72.                 default:
  73.                     System.out.println("Unrecognized menu selected..");
  74.                     break;
  75.             }
  76.         }
  77.     }
  78.  
  79.  
  80.  
  81. ... der følgende konstanter er definert:
  82.  
  83.  
  84.  
  85.     // Constants representing the different menu choices
  86.     private final int ADD_PROPERTY = 1;  
  87.     private final int LIST_ALL_PROPERTIES = 2;
  88.     private final int FIND_PROPERTY = 3;
  89.     private final int CALCULATE_AVERAGE_AREA = 4;
  90.     private final int EXIT = 9;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement