stoyanoff

Menu

Jun 24th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class Menu extends Account {
  7.     Scanner myScan = new Scanner(System.in);
  8.  
  9.     public void displayMenu() {
  10.  
  11.         System.out.println("Please select one of the choices below");
  12.         System.out.println("1 - Balance Check");
  13.         System.out.println("2 - Deposit Money");
  14.         System.out.println("3 - Withdraw Money");
  15.         System.out.println("4 - Exit");
  16.         System.out.print("Choice:");
  17.  
  18.         int choice = myScan.nextInt();
  19.  
  20.         while (choice > 4) {
  21.  
  22.             System.out.println("Wrong choice, please select 1-4 ");
  23.             System.out.print("Choice:");
  24.             choice = myScan.nextInt();
  25.  
  26.         }
  27.         switch (choice) {
  28.  
  29.             case 1:
  30.  
  31.                 displayBalance();
  32.                 returnToMenu();
  33.  
  34.                 break;
  35.             case 2:
  36.                 addBalance();
  37.                 returnToMenu();
  38.                 break;
  39.             case 3:
  40.                 System.out.println("Please Enter the Withdraw Amount");
  41.                 returnToMenu();
  42.             case 4:
  43.                 goodBye();
  44.         }
  45.  
  46.  
  47.     }
  48.  
  49.     public double displayBalance() {
  50.         System.out.print("You Current Account Balance:$");
  51.         System.out.println(accountBalance);
  52.         return accountBalance;
  53.     }
  54.  
  55.     public void addBalance() {
  56.         System.out.print("Please Enter The Amount to Deposit:");
  57.         setAccountBalance(Double.parseDouble(myScan.next()));
  58.         System.out.printf("Your new account balance is:$%.2f\n", accountBalance);
  59.         System.out.println();
  60.  
  61.  
  62.  
  63.     }
  64.  
  65.  
  66.     public void goodBye() {
  67.         System.out.println("Goodbye - and have a nice day");
  68.         System.exit(0);
  69.     }
  70.  
  71.     public void returnToMenu() {
  72.  
  73.         System.out.println("To return in the main menu press 0");
  74.         System.out.println("To exit press 1");
  75.         System.out.print("Choice:");
  76.         int menuChoice = myScan.nextInt();
  77.         if (menuChoice == 0) {
  78.             displayMenu();
  79.         } else {
  80.             goodBye();
  81.  
  82.         }
  83.  
  84.     }
  85. }
Add Comment
Please, Sign In to add comment