-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM.java
More file actions
76 lines (70 loc) · 2.58 KB
/
Copy pathATM.java
File metadata and controls
76 lines (70 loc) · 2.58 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
import java.util.*;
import java.io.IOException;
public class ATM {
public static void access() throws IOException{
Data.method = "ATM";
Scanner input = new Scanner(System.in);
int debitcardindex = 6;
Boolean cardValid = false;
String cardnumber = "";
do{
System.out.print("Enter your debit card number: ");
cardnumber = input.next();
System.out.println("--------------------");
cardValid = numberValidate(cardnumber,debitcardindex);
}
while(cardValid == false);
int threshold = 0;
boolean Valid = false;
String pin = "";
do{
System.out.print("Enter your pin: ");
pin = input.next();
System.out.println("--------------------");
Valid = Validate(cardnumber, debitcardindex, pin, threshold);
threshold++;
}
while(Valid == false && threshold < 4);
if(threshold == 4){
System.out.print("Please wait a few seconds and then try again!");
System.out.println("--------------------");
ATM.access();
}
if(Valid == true){
Transactions.ATM();
}
}
public static boolean numberValidate(String cardnumber, int debitcardindex){
boolean valid = true;
try {
Data.customerarray(cardnumber, debitcardindex);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(Data.customerdata.size() == 0){
System.out.println("Invalid Card Number! Please try again.");
valid = false;
}
else{
try {
Data.card(Data.customerdata.get(0), 0);
Data.generalarray(Data.customerdata.get(0), 0);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return valid;
}
public static boolean Validate(String cardnumber, int debitcardindex, String pin, int threshold){
if(cardnumber.equals(Data.customerdata.get(debitcardindex)) && pin.equals(Data.ATMarray.get(6))){
return true;
}
else{
int triesremaining = 3 - threshold; //caluclates tries remaining
System.out.println("Pin number is wrong! You have " + triesremaining + " try(s) remaining before your card gets suspended!");
return false;
}
}
}