1import java.util.Scanner;
2
3public class ATM {
4 private static Scanner in;
5 private static float balance = 0; // For everyone they will get 0
6 private static int anotherTransaction;
7
8 private static void greetings(){
9 System.out.println("Welcome to bank Pepe Pig you can withdraw, deposit, and balance you have $0");
10 }
11
12 public static void main(String[] args) {
13 in = new Scanner(System.in);
14 greetings();
15 transaction();
16 }
17
18 private static void transaction(){
19 int choice;
20 System.out.println("1. Withdraw ");
21 System.out.println("2. Deposit");
22 System.out.println("3. Balance");
23 System.out.println("---------------------" +
24 "Please select an option: " +
25 "---------------------");
26
27 choice = in.nextInt();
28
29 switch (choice){
30 case 1:
31 float amount;
32 System.out.println("Please enter an amount you would like to withdraw.");
33 amount = in.nextFloat();
34 if (amount > balance || amount == 0){
35 System.out.println("You have a insufficient with your funds\n\n");
36 anotherTransaction(); // If they want another transaction
37 }else{
38 // They have some money
39 // update balance
40 balance = balance - amount;
41 System.out.println("You have withdrawn " + amount + " and your new balance is now. " + balance + "\n");
42 anotherTransaction();
43 }
44 break;
45 case 2:
46 // This is to deposit
47 float deposit;
48 System.out.println("Please enter the amount you would like to put in: ");
49 deposit = in.nextFloat();
50 // update balance
51 balance = deposit + balance;
52 System.out.println("You have deposited " + deposit + " new balance is. " + balance + "\n");
53 anotherTransaction();
54 break;
55 case 3:
56 // to balance
57 System.out.println("Your balance is " + balance + "\n");
58 anotherTransaction();
59 break;
60 }
61 }
62
63 private static void anotherTransaction() {
64 System.out.println("Do you want another transaction? \n\nPress 1 for anotherTransaction \n2 To exit.");
65 anotherTransaction = in.nextInt();
66 if (anotherTransaction == 1){
67 transaction(); // Call method
68 } else if (anotherTransaction == 2){
69 System.out.println("Thank you for banking in bank of leano!");
70 }else{
71 System.out.println("Invalid choice \n\n");
72 anotherTransaction();
73 }
74 }
75}