Added base classes
This commit is contained in:
42
src/main/java/me/zacharias/bank/User.java
Normal file
42
src/main/java/me/zacharias/bank/User.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package me.zacharias.bank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class User {
|
||||
UUID id;
|
||||
String name;
|
||||
String password;
|
||||
ArrayList<Account> accounts;
|
||||
|
||||
public User(String name, String password) {
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
id = UUID.randomUUID();
|
||||
accounts = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void createAccount(String name, int balance) {
|
||||
Account account = new BankAccount(name, balance);
|
||||
accounts.add(account);
|
||||
}
|
||||
|
||||
public void createSavingsAccount(String name, int balance) {
|
||||
Account account = new SavingsAccount(name, balance);
|
||||
accounts.add(account);
|
||||
}
|
||||
|
||||
public void deleteAccount(Account account) {
|
||||
Account base = null;
|
||||
for(Account a : accounts) {
|
||||
if(a instanceof BankAccount) {
|
||||
base = a;
|
||||
}
|
||||
}
|
||||
if(base == null) {
|
||||
throw new IllegalArgumentException("No bank accounts found");
|
||||
}
|
||||
base.TransferTransaction(account.getBalance(), "Account closed", account.getId(), base.getId());
|
||||
accounts.remove(account);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user