Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Menu {
- Scanner myScan = new Scanner(System.in);
- public void printMenu() {
- System.out.println("Choose from the following options");
- System.out.println("1) Balance");
- System.out.println("2) Withdraw");
- System.out.println("3) Deposit");
- System.out.println("4) Exit");
- menuAction(choiceMenu());
- }
- private int choiceMenu() {
- int choice = 0;
- while (choice <= 0 || choice > 4) {
- System.out.print("Enter You choice: ");
- try {
- choice = Integer.parseInt(myScan.nextLine());
- } catch (NumberFormatException e) {
- System.out.println("Numbers only");
- }
- if (choice <= 0 || choice > 4) {
- System.out.println("Invalid Choice number 1-4");
- }
- }
- return choice;
- }
- private void menuAction(int choice) {
- switch (choice) {
- case 1:
- System.out.println("Balance Menu");
- //balanceMenu();
- break;
- case 2:
- System.out.println("Withdraw Menu");
- //withdrawMenu();
- break;
- case 3:
- System.out.println("Deposit Menu");
- break;
- case 4:
- System.out.println("Thank you for using our ATM");
- System.exit(0);
- break;
- default:
- System.out.println("Error");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment