stoyanoff

ATM

Jun 23rd, 2020
2,905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.text.*;
  4. import java.util.*;
  5.  
  6. public class Main {
  7.  
  8.     static double balance = 100;
  9.     static double depositAdd = 0;
  10.     static double withdrawAmount = 0;
  11.     static Scanner myScan = new Scanner(System.in);
  12.     static SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yy");
  13.     static Date newDate = new Date();
  14.  
  15.     public static void main(String[] args) {
  16.  
  17.         System.out.printf("Welcome - ATM \nDate: %s", newDateFormat.format(newDate));
  18.         System.out.println();
  19.         System.out.println();
  20.         System.out.println("Please Select Your Choice:");
  21.         menuCall();
  22.  
  23.  
  24.     }
  25.  
  26.     private static void menuCall() {
  27.  
  28.         System.out.println("To Check Your Balance - Please Press: 1");
  29.         System.out.println("To Make a Deposit - Please Press: 2");
  30.         System.out.println("To Make a Withdraw - Please Press: 3");
  31.         System.out.println("To Exit - Please Press: 4");
  32.         System.out.print("Your Choice:");
  33.  
  34.         int choiceMenu = Integer.parseInt(myScan.next());
  35.  
  36.         menu(choiceMenu);
  37.     }
  38.  
  39.  
  40.     private static void menu(int menu) {
  41.  
  42.         switch (menu) {
  43.             case 1:
  44.                 balanceCheck(balance);
  45.                 break;
  46.             case 2:
  47.                 depositAdd(depositAdd);
  48.                 break;
  49.             case 3:
  50.                 withdraw(withdrawAmount);
  51.                 break;
  52.             case 4:
  53.                 System.out.println("Goodbye - Have a nice day!");
  54.                 return;
  55.  
  56.         }
  57.     }
  58.  
  59.     private static void balanceCheck(double balance) {
  60.         System.out.print("Your Account Balance:$");
  61.         System.out.println(balance);
  62.         System.out.println();
  63.         System.out.println();
  64.         System.out.print("Press 4 to return to the main menu:");
  65.         int choice = Integer.parseInt(myScan.next());
  66.         while (choice != 4) {
  67.             System.out.println("Wrong Input");
  68.             System.out.print("Please Press 4 to return to the main menu:");
  69.             choice = Integer.parseInt(myScan.next());
  70.  
  71.         }
  72.         menuCall();
  73.  
  74.  
  75.     }
  76.  
  77.     private static void depositAdd(double depositAdd) {
  78.         System.out.print("Please Enter the Amount of the Deposit:");
  79.         depositAdd = Double.parseDouble(myScan.next());
  80.         System.out.println(depositAdd);
  81.         balance = balance + depositAdd;
  82.         System.out.print("Your new Balance is:$");
  83.         System.out.println(balance);
  84.         System.out.println();
  85.         System.out.println();
  86.         System.out.print("Press 4 to return to menu:");
  87.         int choice = Integer.parseInt(myScan.next());
  88.         while (choice != 4) {
  89.             System.out.println("Wrong Input");
  90.             System.out.print("Please Press 4 to return to the main menu:");
  91.             choice = Integer.parseInt(myScan.next());
  92.  
  93.         }
  94.         menuCall();
  95.     }
  96.  
  97.     private static void withdraw(double withdrawAmount) {
  98.         do {
  99.             System.out.print("Please Enter the Amount to withdraw:$");
  100.             withdrawAmount = Double.parseDouble(myScan.next());
  101.             if (withdrawAmount > balance) {
  102.                 System.out.println("Not enough funds in your account");
  103.                 System.out.println();
  104.                 System.out.print("Please enter new amount:");
  105.                 withdrawAmount = Double.parseDouble(myScan.next());
  106.             } else
  107.                 continue;
  108.  
  109.         } while (balance < withdrawAmount);
  110.  
  111.         balance = balance - withdrawAmount;
  112.         System.out.printf("Your new balance is:$%.2f", balance);
  113.         System.out.println();
  114.         System.out.print("Press 4 to return to menu:");
  115.         int choice = Integer.parseInt(myScan.next());
  116.         while (choice != 4) {
  117.             System.out.println("Wrong Input");
  118.             System.out.print("Please Press 4 to return to the main menu:");
  119.             choice = Integer.parseInt(myScan.next());
  120.  
  121.         }
  122.         menuCall();
  123.  
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment