-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM INTERFACE.java
252 lines (246 loc) · 7.71 KB
/
ATM INTERFACE.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import java.util.Scanner;
class Account
{
String name;
String userName;
String password;
int accountNo;
float balance=100000f;
int transactions=0;
String transactionHistroy="";
public void Register()
{
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter 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.nextInt();
System.out.println("");
System.out.println("Registration Completed Successfully Congratulation...!!");
System.out.println("-------------------------------------------------------");
System.out.println("Now Login to Your Account-->");
}
public boolean Login()
{
boolean isLogin=false;
Scanner sc=new Scanner(System.in);
while(!isLogin)
{
System.out.print("\nEnter 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.println("\nLogged In Succesfully");
System.out.println("---------------------");
isLogin=true;
}
else
{
System.out.println("Incorrect Password");
}
}
}
else
{
System.out.println("Sorry Username NOT FOUND!!!");
}
}
return isLogin;
}
public void withdraw()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the amount you want to withdraw: ");
float amount=sc.nextFloat();
try
{
if(balance>=amount)
{
transactions++;
balance=balance-amount;
System.out.println("\nWithdrawal Succesfully...!\n");
String str="Rs "+amount+" Withdrawn from your Account.\n";
transactionHistroy=transactionHistroy.concat(str);
}
else
{
System.out.println("Insufficient Balance!!");
}
}
catch(Exception e){
}
}
public void deposite()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the amount to be deposited: ");
float amount=sc.nextFloat();
try{
if(amount<=100000f)
{
transactions++;
balance=balance+amount;
System.out.println("\nAmount Deposited Successfully.\n");
String str="Rs "+amount+" Deposited in your Account.\n";
transactionHistroy=transactionHistroy.concat(str);
}
else
{
System.out.println("Limit ids of 100000.00");
}
}
catch(Exception e){
}
}
public void transfer()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Recepient Name: ");
String RepName=sc.nextLine();
System.out.print("Enter the amount: ");
float amount=sc.nextFloat();
try
{
if(balance>=amount)
{
if(amount<=50000f)
{
transactions++;
balance-=amount;
System.out.println("\nTransfered Sucessfully to "+RepName+".\n");
String str="Rs "+amount+" transfer to "+RepName+".";
transactionHistroy=transactionHistroy.concat(str);
}
else
{
System.out.println("SORRY Limit Is Of Rs 50000.00");
}
}
else
{
System.out.println("Insuffient Balance");
}
}
catch(Exception e){
}
}
public void checkBalance()
{
System.out.println("\nBalance:--> "+balance);
System.out.println("---------------------------");
}
public void transactionHis()
{
if(transactions==0)
{
System.out.println("Empty");
}
else
{
System.out.print("\n"+transactionHistroy+"\n");
System.out.println("------------------------");
}
}
}
class ATMInterface
{
public static int takeInetegerInput(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.print("Select The number between 1 and "+limit+":");
flag=false;
}
}
catch(Exception e)
{
System.out.print("Enter Integer value: ");
flag=false;
}
}
return input;
}
public static void main(String [] args)
{
System.out.println("\n***** Welcome TO SBI ATM SYSTEM *****\n");
System.out.println("1.REGISTER\n2.EXIT");
System.out.println("---------------------");
System.out.print("Enter Your Option: ");
int choice=takeInetegerInput(2);
if(choice==1)
{
Account b=new Account();
b.Register();
while(true)
{
System.out.println("1.LOGIN\n2.EXIT");
System.out.println("------------------------");
System.out.print("Enter Your Option: ");
int ch=takeInetegerInput(2);
if(ch==1)
{
if(b.Login())
{
System.out.println("\n<----Welcome Back "+b.name+"---->");
boolean isFinish=false;
while(!isFinish)
{
System.out.print("O-P-T-I-O-N-S:-\n1.Deposit\n2.WithDraw\n3.Transfer\n4.Transaction Histroy\n5.Check balance\n6.Exit\n");
System.out.println("------------------");
System.out.print("Enter your option: ");
int c=takeInetegerInput(6);
switch(c)
{
case 1:
b.deposite();
break;
case 2:
b.withdraw();
break;
case 3:
b.transfer();
break;
case 4:
b.transactionHis();
break;
case 5:
b.checkBalance();
break;
case 6:
isFinish=true;
break;
}
}
}
}
else
{
System.exit(0);
}
}
}
else
{
System.exit(0);
}
}
}