-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankSystem.java
More file actions
33 lines (27 loc) · 1 KB
/
BankSystem.java
File metadata and controls
33 lines (27 loc) · 1 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
import java.util.HashMap;
public class BankSystem {
private HashMap<String, BankAccount> accounts;
public BankSystem() {
accounts = new HashMap<>();
}
public void createAccount(String username, String name, String accountType, double initialBalance) {
Person person = new Person(username, name);
BankAccount account;
switch (accountType.toLowerCase()) {
case "savings":
account = new SavingsAccount(person, initialBalance);
break;
case "checking":
account = new CheckingAccount(person, initialBalance);
break;
default:
System.out.println("Invalid account type.");
return;
}
accounts.put(username, account);
System.out.println("Account created for " + name + " with account number " + account.getAccountNumber());
}
public BankAccount getAccount(String username) {
return accounts.get(username);
}
}