Added base classes

This commit is contained in:
2025-03-19 12:51:30 +01:00
parent c05dda145f
commit 32c93fd99f
8 changed files with 333 additions and 0 deletions

View 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);
}
}