Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.text.*;
- import java.util.*;
- public class Main {
- static double balance = 100;
- static double depositAdd = 0;
- static double withdrawAmount = 0;
- static Scanner myScan = new Scanner(System.in);
- static SimpleDateFormat newDateFormat = new SimpleDateFormat("dd/MM/yy");
- static Date newDate = new Date();
- public static void main(String[] args) {
- System.out.printf("Welcome - ATM \nDate: %s", newDateFormat.format(newDate));
- System.out.println();
- System.out.println();
- System.out.println("Please Select Your Choice:");
- menuCall();
- }
- private static void menuCall() {
- System.out.println("To Check Your Balance - Please Press: 1");
- System.out.println("To Make a Deposit - Please Press: 2");
- System.out.println("To Make a Withdraw - Please Press: 3");
- System.out.println("To Exit - Please Press: 4");
- System.out.print("Your Choice:");
- int choiceMenu = Integer.parseInt(myScan.next());
- menu(choiceMenu);
- }
- private static void menu(int menu) {
- switch (menu) {
- case 1:
- balanceCheck(balance);
- break;
- case 2:
- depositAdd(depositAdd);
- break;
- case 3:
- withdraw(withdrawAmount);
- break;
- case 4:
- System.out.println("Goodbye - Have a nice day!");
- return;
- }
- }
- private static void balanceCheck(double balance) {
- System.out.print("Your Account Balance:$");
- System.out.println(balance);
- System.out.println();
- System.out.println();
- System.out.print("Press 4 to return to the main menu:");
- int choice = Integer.parseInt(myScan.next());
- while (choice != 4) {
- System.out.println("Wrong Input");
- System.out.print("Please Press 4 to return to the main menu:");
- choice = Integer.parseInt(myScan.next());
- }
- menuCall();
- }
- private static void depositAdd(double depositAdd) {
- System.out.print("Please Enter the Amount of the Deposit:");
- depositAdd = Double.parseDouble(myScan.next());
- System.out.println(depositAdd);
- balance = balance + depositAdd;
- System.out.print("Your new Balance is:$");
- System.out.println(balance);
- System.out.println();
- System.out.println();
- System.out.print("Press 4 to return to menu:");
- int choice = Integer.parseInt(myScan.next());
- while (choice != 4) {
- System.out.println("Wrong Input");
- System.out.print("Please Press 4 to return to the main menu:");
- choice = Integer.parseInt(myScan.next());
- }
- menuCall();
- }
- private static void withdraw(double withdrawAmount) {
- do {
- System.out.print("Please Enter the Amount to withdraw:$");
- withdrawAmount = Double.parseDouble(myScan.next());
- if (withdrawAmount > balance) {
- System.out.println("Not enough funds in your account");
- System.out.println();
- System.out.print("Please enter new amount:");
- withdrawAmount = Double.parseDouble(myScan.next());
- } else
- continue;
- } while (balance < withdrawAmount);
- balance = balance - withdrawAmount;
- System.out.printf("Your new balance is:$%.2f", balance);
- System.out.println();
- System.out.print("Press 4 to return to menu:");
- int choice = Integer.parseInt(myScan.next());
- while (choice != 4) {
- System.out.println("Wrong Input");
- System.out.print("Please Press 4 to return to the main menu:");
- choice = Integer.parseInt(myScan.next());
- }
- menuCall();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment