forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionMenu.java
118 lines (102 loc) · 3.76 KB
/
OptionMenu.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
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Scanner;
public class OptionMenu extends Account {
Scanner menuInput = new Scanner(System.in);
DecimalFormat moneyFormat = new DecimalFormat("'$'###,##0.00");
HashMap<Integer, Integer> data = new HashMap<>();
public void getLogin() {
int x = 1;
do{
try{
data.put(952141, 191904);
data.put(989947, 717976);
System.out.println("Welcome to ATM");
System.out.println("Enter your Customer Number");
setCustomerNumber(menuInput.nextInt());
System.out.println("Enter your PIN Number");
setPinNumber(menuInput.nextInt());
}
catch(Exception e){
System.out.println("\nInvalid Characters Only Numbers Allowed\n" + e);
x = 2;
}
int cn = getCustomerNumber();
int pn = getPinNumber();
if(data.containsKey(cn) && data.get(cn) == pn){
getAccountType();
}
else{
System.out.println("\nWrong Customer Number or Wrong PIN Number\n\n");
}
}while(x == 1);
}
public void getAccountType() {
System.out.println("Select Account Type you want to Access");
System.out.println("Type 1 - Checking Account");
System.out.println("Type 2 - Savings Account");
System.out.println("Type 3 - Exit");
int selection = menuInput.nextInt();
switch (selection) {
case 1 -> getChecking();
case 2 -> getSaving();
case 3 -> System.out.println("Thank you for using ATM, BYE\n");
default -> System.out.println("\n Invalid Choice \n");
}
}
public void getChecking() {
System.out.println("Checking Account");
System.out.println("Type 1 - View Balance");
System.out.println("Type 2 - Withdraw Money");
System.out.println("Type 3 - Deposit Funds");
System.out.println("Type 4 - Exit");
int selection = menuInput.nextInt();
switch (selection) {
case 1 -> {
System.out.println("Checking Account Balance: " + moneyFormat.format(getCheckingBalance()));
getAccountType();
}
case 2 -> {
getCheckingWithdrawInput();
getAccountType();
}
case 3 -> {
getCheckingDepositInput();
getAccountType();
}
case 4 -> System.out.println("Thank you for using ATM, Bye");
default -> {
System.out.println("\nInvalid Choice\n");
getChecking();
}
}
}
public void getSaving() {
System.out.println("Saving Account");
System.out.println("Type 1 - View Balance");
System.out.println("Type 2 - Withdraw Money");
System.out.println("Type 3 - Deposit Funds");
System.out.println("Type 4 - Exit");
System.out.print("Choice: ");
int selection = menuInput.nextInt();
switch (selection) {
case 1 -> {
System.out.println("Saving Account Balance: " + moneyFormat.format(getSavingBalance()));
getAccountType();
}
case 2 -> {
getSavingWithdrawInput();
getAccountType();
}
case 3 -> {
getSavingDepositInput();
getAccountType();
}
case 4 -> System.out.println("Thank you for using ATM, Bye\n");
default -> {
System.out.println("\nInvalid Choice\n");
getChecking();
}
}
}
}