-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM.java
96 lines (92 loc) · 2.89 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.util.*;
public class ATM{
public static void main(String[] args) {
ATMop obj = new ATMop();
}
}
class Data{
float balance;
}
class ATMop{
//float balance;
Scanner sc = new Scanner(System.in);
HashMap <Integer,Data> map=new HashMap<>();
ATMop(){
System.out.println("*************************************************");
System.out.println("Welcome to our ATM");
op();
}
public void op(){
System.out.println("*************************************************");
System.out.println("Enter valid pin:");
int pincode = sc.nextInt();
if((map.containsKey(pincode))==true){
Data obj = map.get(pincode);
menu(obj);
}
else{
System.out.println("*************************************************");
System.out.println("Please create your account first");
System.out.println("Set up your pincode:");
int pin = sc.nextInt();
Data obj = new Data();
map.put(pin , obj);
menu(obj);
}
}
public void menu(Data obj){
System.out.println("*************************************************");
System.out.println("Please enter your choice:");
System.out.println("1.Check Balance");
System.out.println("2. Deposit Money");
System.out.println("3.Withdraw Money");
System.out.println("4.Check another account");
System.out.println("5.Exit");
int x = sc.nextInt();
if(x==1){
check_balance(obj);
}
else if(x==2){
deposit(obj);
}
else if(x==3){
withdraw(obj);
}
else if(x==4){
op();
}
else if(x==5){
System.out.println("Thank You!");
}
else{
System.out.println("Please enter a valid number");
menu(obj);
}
}
public void check_balance(Data obj){
System.out.println("*************************************************");
System.out.println("Your Balance:"+obj.balance);
menu(obj);
}
public void deposit(Data obj){
System.out.println("*************************************************");
System.out.println("Enter your amount:");
float a = sc.nextFloat();
obj.balance= obj.balance + a;
System.out.println("Amount deposited successfully!");
menu(obj);
}
public void withdraw(Data obj){
System.out.println("*************************************************");
System.out.println("Enter your amount:");
float a = sc.nextFloat();
if(obj.balance >= a){
obj.balance= obj.balance - a;
System.out.println("Amount withdrawn successfully!");
}
else{
System.out.println("Insufficient balance");
}
menu(obj);
}
}