-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMOperations.java
More file actions
88 lines (85 loc) · 3.06 KB
/
ATMOperations.java
File metadata and controls
88 lines (85 loc) · 3.06 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
import java.util.Arrays;
import java.util.Scanner;
public class ATMOperations {
double balance;
final private String[] users= {"new1","new2","new3"};
final private String[] passwords={"ouds","yza","irsa"};
boolean checkPassword(String user,String password) {
boolean checkPass=false;
String[] userCheck=this.users;
String[] passwordCheck=this.passwords;
if((Arrays.asList(passwordCheck).contains(password)) && (Arrays.asList(userCheck).contains(user))){
checkPass=true;
}
return checkPass;
}
double checkBalance() {
return balance;
}
boolean withDrawAmount(double amount) {
boolean succuss=false;
if(balance>=amount) {
balance-=amount;
succuss=true;
}
return succuss;
}
boolean depositeAmount(double amount) {
boolean succuss=false;
if(amount>0) {
balance+=amount;
succuss=true;
}
return succuss;
}
public static void main(String[] args) {
boolean exit = false;
try (Scanner sc = new Scanner(System.in)) {
ATMOperations ob1=new ATMOperations();
System.err.println("Enter User Name From Following:");
for (String user1 : ob1.users) {
System.err.println(user1);
}
String user= sc.nextLine();
System.out.println("Enter the your Password:");
String pass=sc.nextLine();
if(ob1.checkPassword(user,pass)==false) {
System.out.println("Invalid Password... Access Denied");
sc.close();
exit=true;
}
while(!exit) {
System.out.println("1.Check Balance");
System.out.println("2.Deposite Amount");
System.out.println("3.Withdraw Amount");
System.out.println("4.Exit");
int op=sc.nextInt();
switch(op) {
case 1 -> System.out.println("Your Current Balance="+ob1.checkBalance());
case 2 -> {
System.out.println("Enter Amount to Deposite:");
double am1=sc.nextDouble();
if(ob1.depositeAmount(am1)) {
System.out.println(am1+" is succussfully Deposited..");
}else {
System.out.println(am1+" is Invalid Amount");
}
}
case 3 -> {
System.out.println("Enter Amount to Withdraw:");
double am2=sc.nextDouble();
if(ob1.withDrawAmount(am2)) {
System.out.println(am2+" is succussfully Withdrawn..");
}else {
System.out.println("Insuffient Balance");
}
}
case 4 -> {
exit=true;
System.out.println("Thank you for Using Our Services");
}
}
}
}
}
}