package bank; //... public class Bank { private Map<String, BankAccount> accounts; public Bank() { this.accounts = new HashMap<String,BankAccount>(); public void addaccount(bankaccount account) { this.accounts.put(account.getnumber(), account); public void displaybalance(string accountnumber) { float value = this.accounts.get(accountnumber).getbalance(); System.out.println("balance of account n "+accountnumber+" : "+value); public void creditaccount(string accountnumber, float amount) { this.accounts.get(accountnumber).credit(amount); public void withdraw(string accountnumber, float amount) { this.accounts.get(accountnumber).withdraw(amount); // and other methods handling BankAccount... public static void main(string[] args) { Bank bank = new Bank(); bank.addaccount(new ProtectedBankAccount(new Person(),"number1",0)); bank.addaccount(new BonusBankAccount(new Person(),"number2",0.01f)); bank.creditaccount("number1", 1000); bank.creditaccount("number2", 500); bank.displaybalance("number2"); bank.withdraw("number1",444);
import java.util.date; import java.util.list; public interface BankAccount { public Person getowner(); public String getnumber(); public float getbalance(); public void credit(float amount); public void withdraw(float amount); public List<Operation> getoperationsafter(date time);
public class StandardBankAccount implements BankAccount { public StandardBankAccount(Person owner, String number) {
public class ProtectedBankAccount implements BankAccount { private float lowerbound; public ProtectedBankAccount(Person owner, String number, float lowerbound){ this.lowerbound = lowerbound; if (this.balance-amount >= this.lowerbound) { // else nothing... or an exception to be thrown public float getlowerbound() { return this.lowerbound;
public class BonusBankAccount implements BankAccount { private float bonusrate; public BonusBankAccount(Person owner, String number, float bonusrate) { this.bonusrate = bonusrate; this.balance = this.balance + (amount*this.bonusrate); public float getbonusrate() { return this.bonusrate;
public class *****BankAccount implements BankAccount { public *****BankAccount(Person owner, String number *****) {