-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM.java
78 lines (62 loc) · 2.79 KB
/
ATM.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.Scanner;
public class ATM
{
// private float balance = 0;
private static void transaction(float balance) {
System.out.println("\nEnter any option to be served!\n");
System.out.println("1. Withdraw");
System.out.println("2. Deposit");
System.out.println("3. Balance\n");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
int choice = Integer.parseInt(input);
int amountToWithDraw, amountToDeposit, anotherTransaction;
switch( choice )
{
case 1:
System.out.println("\nPlease enter to withdraw: ");
amountToWithDraw = scanner.nextInt();
if (amountToWithDraw > balance){
System.out.println("There is no insufficient funds in you account");
System.out.println("Do you want another transaction?\nPress 1 to proceed and 2 to exit\n");
anotherTransaction = scanner.nextInt();
if (anotherTransaction == 1){
transaction(balance);
}
}
else {
balance -= amountToWithDraw;
System.out.println("You have withdrawn $" + amountToWithDraw + ".00 and your new balance is " + balance);
System.out.println("Do you want another transaction?\nPress 1 to proceed and 2 to exit\n");
anotherTransaction = scanner.nextInt();
if (anotherTransaction == 1){
transaction(balance);
}
}
break;
case 2:
System.out.println("\nPlease enter amount to deposit: ");
amountToDeposit = scanner.nextInt();
balance += amountToDeposit;
System.out.println("Thank you for depositing" + amountToDeposit + ", new balance is: $" + balance);
System.out.println("Do you want another transaction?\nPress 1 to proceed and 2 to exit\n");
anotherTransaction = scanner.nextInt();
if (anotherTransaction == 1){
transaction(balance);
}
break;
case 3:
System.out.println("\nYour bank balance is: $" + balance);
System.out.println("Do you want another transaction?\nPress 1 to proceed and 2 to exit\n");
anotherTransaction = scanner.nextInt();
if (anotherTransaction == 1){
transaction(balance);
}
break;
}
}
public static void main(String args[]) {
float balance = 0;
transaction(balance);
}
}