-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionMenu.java
117 lines (115 loc) · 4.34 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
package com.supriya;
import java.text.DecimalFormat;
import java.util.*;
import java.io.IOException;
public class OptionMenu extends Account {
Scanner menuInput = new Scanner(System.in);
DecimalFormat moneyFormat = new DecimalFormat("'$',###.00");
HashMap<Integer, Integer> data = new HashMap<Integer, Integer>();
public void getLogin() throws IOException {
int x = 1;
do {
try {
// account privalges
data.put(989947, 71976);
data.put(765432,5656);
System.out.println("Welcome to the ATM Project!");
System.out.println("Enter your customer Number");
setCustomerNumber(menuInput.nextInt());
System.out.print("Enter your PIN Number: ");
setPinNumber(menuInput.nextInt());
} catch (Exception e) {
System.out.println("\n" + "Invalid Character(s). Only Numbers." + "\n");
x = 2;
}
int cn = getCustomerNumber();
int pn = getPinNumber();
//data.get(key) return its value i.e pin number
//containsKey is used to check whether particular key is being mapped or not return true if it mapped then returns false
if (data.containsKey(cn) && data.get(cn) == pn) {
getAccountType();
} else
System.out.println("\n" + "Wrong Customer Number or Pin Number" + "\n");
} while (x == 1);
}
public void getAccountType() {
System.out.println("Select the Account you Want to Access: ");
System.out.println(" Type 1 - Checking Account");
System.out.println(" Type 2 - Saving Account");
System.out.println(" Type 3 - Exit");
int selection = menuInput.nextInt();
switch (selection) {
case 1:
getChecking();
break;
case 2:
getSaving();
break;
case 3:
System.out.println("Thank You for using this ATM, bye. \n");
break;
default:
System.out.println("\n" + "Invalid Choice." + "\n");
getAccountType();
}
}
public void getChecking() {
System.out.println("Checking Account: ");
System.out.println(" Type 1 - View Balance");
System.out.println(" Type 2 - Withdraw Funds");
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("Checking Account Balance: " + moneyFormat.format(getCheckingBalance()));
//2new Swing();
//getAccountType();
break;
case 2:
getCheckingWithdrawInput();
getAccountType();
break;
case 3:
getCheckingDepositInput();
getAccountType();
break;
case 4:
System.out.println("Thank You for using this ATM, bye.");
break;
default:
System.out.println("\n" + "Invalid Choice." + "\n");
getChecking();
}
}
public void getSaving() {
System.out.println("Saving Account: ");
System.out.println(" Type 1 - View Balance");
System.out.println(" Type 2 - Withdraw Funds");
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();
break;
case 2:
getsavingWithdrawInput();
getAccountType();
break;
case 3:
getSavingDepositInput();
getAccountType();
break;
case 4:
System.out.println("Thank You for using this ATM, bye.");
break;
default:
System.out.println("\n" + "Invalid Choice." + "\n");
getChecking();
}
}
}