stoyanoff

Menu

Jul 5th, 2020
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Menu {
  7.     Scanner myScan = new Scanner(System.in);
  8.  
  9.  
  10.     public void printMenu() {
  11.         System.out.println("Choose from the following options");
  12.         System.out.println("1) Balance");
  13.         System.out.println("2) Withdraw");
  14.         System.out.println("3) Deposit");
  15.         System.out.println("4) Exit");
  16.         menuAction(choiceMenu());
  17.     }
  18.  
  19.     private int choiceMenu() {
  20.         int choice = 0;
  21.         while (choice <= 0 || choice > 4) {
  22.             System.out.print("Enter You choice: ");
  23.             try {
  24.                 choice = Integer.parseInt(myScan.nextLine());
  25.  
  26.             } catch (NumberFormatException e) {
  27.                 System.out.println("Numbers only");
  28.  
  29.             }
  30.             if (choice <= 0 || choice > 4) {
  31.                 System.out.println("Invalid Choice number 1-4");
  32.  
  33.             }
  34.  
  35.         }
  36.         return choice;
  37.     }
  38.  
  39.     private void menuAction(int choice) {
  40.  
  41.         switch (choice) {
  42.             case 1:
  43.                 System.out.println("Balance Menu");
  44.                 //balanceMenu();
  45.                 break;
  46.             case 2:
  47.                 System.out.println("Withdraw Menu");
  48.                 //withdrawMenu();
  49.                 break;
  50.             case 3:
  51.                 System.out.println("Deposit Menu");
  52.                 break;
  53.             case 4:
  54.                 System.out.println("Thank you for using our ATM");
  55.                 System.exit(0);
  56.                 break;
  57.             default:
  58.                 System.out.println("Error");
  59.         }
  60.     }
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment