-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMInterface.java
More file actions
220 lines (189 loc) · 7.75 KB
/
ATMInterface.java
File metadata and controls
220 lines (189 loc) · 7.75 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import java.util.Scanner;
class Account {
String name;
String username;
String password;
String accountNo;
float balance = 100000f;
int transaction = 0;
String transactionHistory = "";
public void register() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name : ");
this.name = sc.nextLine();
System.out.print("Enter your username : ");
this.username = sc.nextLine();
System.out.print("Enter your password : ");
this.password = sc.nextLine();
System.out.print("Enter your Account Number : ");
this.accountNo = sc.nextLine();
System.out.print("REGISTRATION COMPLETE --- PLEASE LOG IN!");
}
public boolean login() {
boolean isLogin = false;
Scanner sc = new Scanner(System.in);
while(! isLogin){
System.out.print("Enter your username : ");
String Username = sc.nextLine();
if(Username.equals(username)){
while(!isLogin){
System.out.print("Enter your password : ");
String Password = sc.nextLine();
if(Password.equals(password)){
System.out.print("Log in successfull!");
isLogin = true;
} else {
System.out.print("\nIncorrect Password");
}
}
} else {
System.out.print("\nUsername not found!");
}
} return isLogin;
}
public void withdraw() {
System.out.print("Enter the amount to withdraw : ");
Scanner sc = new Scanner(System.in);
float amount = sc.nextFloat();
try {
if(balance >= amount)
{
transaction++;
balance -=amount;
System.out.println("\nWithdraw Successfull!!");
String str = amount+"Rs Withdrawed\n";
transactionHistory = transactionHistory.concat(str);
} else {
System.out.println("\n Insufficient Amount!");
}
} catch(Exception e) {
}
}
public void deposit() {
System.out.print("\nEnter the amount to be deposited : ");
Scanner sc = new Scanner(System.in);
float amount=sc.nextFloat();
try {
if(amount<=100000f)
{
transaction++;
balance += amount;
System.out.println("\nSuccessfully deposited");
String str = amount+"Rs deposited\n";
transactionHistory=transactionHistory.concat(str);
} else {
System.out.println("\nSorry..!! Limit is 100000.00");
}
}
catch (Exception e){
}
}
public void transfer() {
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter Receipent Name : ");
String receipent=sc.nextLine();
System.out.print("\nEnter the Amount to be transferred : ");
float amount = sc.nextFloat();
try{
if (balance >=amount){
if (amount <= 50000f) {
transaction++;
balance -=amount;
System.out.println("\nSuccessfully transferred to "+receipent);
String str = amount+"Rs transferred to "+receipent+"\n";
transactionHistory=transactionHistory.concat(str);
}
else {
System.out.println("\nSorry limit is 50000");
}
} else {
System.out.println("\nInsufficient Balance");
}
}
catch(Exception e) {
}
}
public void checkBalance(){
System.out.println("\n"+balance+"Rs");
}
public void transactionHistory(){
if(transaction==0) {
System.out.println("\nEmpty");
} else {
System.out.println("\n"+transactionHistory);
}
}
}
public class ATMInterface {
public static int
takeIntegerInput(int limit){
int input=0;
boolean flag=false;
while(!flag){
try {
Scanner sc = new Scanner(System.in);
input=sc.nextInt();
flag=true;
if(flag && input > limit || input <1) {
System.out.println("Choose the number between 1 to "+limit);
flag = false;
}
}
catch(Exception e) {
System.out.print("Enter only integer value : ");
flag = false;
}
};
return input;
}
public static void main (String[]args) {
System.out.println("\n**********WELCOME TO THE ATM********");
System.out.println("1. Register \n2. Exit");
System.out.print("Enter your choice : ");
int choice =takeIntegerInput(2);
if(choice==1) {
Account b = new Account();
b.register();
while(true){
System.out.println("\n1. Log In \n2. Exit");
System.out.print("Enter your choice : ");
int ch=takeIntegerInput(2);
if(ch==1) {
if(b.login()) {
System.out.println("\n\n********Welcome Back "+b.name+"********\n");
boolean isFinished=false;
while(!isFinished) {
System.out.println("\n1. Withdraw\n2. Deposit\n3. Transfer\n4. Check Balance\n5. Transaction History\n6. Exit");
System.out.print("Enter your choice : ");
int c=takeIntegerInput(6);
switch(c) {
case 1:
b.withdraw();
break;
case 2:
b.deposit();
break;
case 3:
b.transfer();
break;
case 4:
b.checkBalance();
break;
case 5:
b.transactionHistory();
break;
case 6:
isFinished=true;
break;
}
}
}
} else {
System.exit(0);
}
}
} else {
System.exit(0);
}
}
}