-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATMInterface.java
98 lines (84 loc) · 2.83 KB
/
ATMInterface.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.util.*;
class BankAccount{
private int balance;
public BankAccount(int initialAmount){
this.balance = initialAmount;
}
public int balance(){
return balance;
}
public void deposit(int amount){
if (amount > 0){
balance += amount;
System.out.println("Deposit of " + amount + "Rs was successfull");
} else {
System.out.println("Invalid entry!. Please choose a number above 0");
}
}
public void withdraw(int amount){
if (amount > 0 && amount <= balance){
System.out.println("Withdraw successfull of "+amount+"Rs");
amount -= balance;
} else {
System.out.println("Invaid entry!!.Insuffucient balance or negative value entered");
}
}
}
class ATM{
private BankAccount account;
public ATM(BankAccount account){
this.account = account;
}
public void display(){
System.out.println("Select Options");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Check Balance");
System.out.println("4. Leave");
}
public void run(){
Scanner sc = new Scanner(System.in);
int option;
do{
display();
System.out.println("Pick an option");
option = sc.nextInt();
switch (option){
case 1:
System.out.println("Enter amount to deposit");
int depositAmount = sc.nextInt();
account.deposit(depositAmount);
break;
case 2:
System.out.println("Enter amount to withdraw");
int withdrawAmount = sc.nextInt();
account.withdraw(withdrawAmount);
break;
case 3:
System.out.println("Current balance " + account.balance());
break;
case 4:
System.out.println("Thanks for working with Jain Bank");
break;
default:
System.out.println("Invalid entry!!. Enter only the given options");
}
}while (option != 4);
sc.close();;
}
}
public class ATMInterface {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BankAccount userAccount = new BankAccount(30000);
ATM atm = new ATM(userAccount);
System.out.println("Enter Your PIN");
int pin = sc.nextInt();
if (pin == 1234) {
atm.run();
} else {
System.out.println("Wrong pin");
}
//lets test the code
}
}