-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathAccountMenu.java
More file actions
54 lines (42 loc) · 1.73 KB
/
AccountMenu.java
File metadata and controls
54 lines (42 loc) · 1.73 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
package atmproject;
import atmproject.accounts.Account;
import atmproject.accounts.InvestmentsAccount;
import atmproject.accounts.SavingsAccount;
import java.util.LinkedHashMap;
import java.util.Map;
public class AccountMenu {
Account returnedAccount;
Console console = new Console(System.in, System.out);
public Account selectAccount(User user) {
Map<Integer, Account> returnedMap = new LinkedHashMap<>();
returnedAccount = null;
Integer counter = 1;
printAndStoreAccounts(user, returnedMap, counter);
returnedAccount = getUserSelectedAccount(returnedMap, returnedAccount);
return returnedAccount;
}
public Account getUserSelectedAccount(Map<Integer, Account> returnedMap, Account returnedAccount) {
while (returnedAccount == null) {
console.println("\nPlease select an account.");
Integer input = console.getIntegerInput(":");
returnedAccount = getUsersInput(returnedMap, returnedAccount, input);
}
return returnedAccount;
}
public Account getUsersInput(Map<Integer, Account> returnedMap, Account returnedAccount, Integer input) {
if (returnedMap.containsKey(input)) {
returnedAccount = returnedMap.get(input);
} else {
console.println("\nAccount does not exist. Try again: ");
}
return returnedAccount;
}
public void printAndStoreAccounts(User user, Map<Integer, Account> returnedMap, Integer counter) {
console.println("\n");
for (String s : user.accountList.keySet()) {
console.println("(" + counter + ")" + " - " + s);
returnedMap.put(counter, user.accountList.get(s));
counter++;
}
}
}