Skip to content

Commit

Permalink
Update SavingsAccount.java
Browse files Browse the repository at this point in the history
  • Loading branch information
JitseGoutbeek authored Jun 28, 2024
1 parent 6b72002 commit 1fd61fb
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package eu.sig.training.ch04;
package eu.sig.training.ch04.v3;

import eu.sig.training.ch04.BusinessException;
import eu.sig.training.ch04.Money;

// tag::SavingsAccount[]
public class SavingsAccount {
private static final float INTEREST_PERCENTAGE = 0.05f;
private Money balance = new Money();
private CheckingAccount counterAccount = new CheckingAccount();
public class SavingsAccount extends Account {
CheckingAccount registeredCounterAccount;

public void setaccountnumber(CheckingAccount account) {
this.counteraccount = account;
}
public Transfer makeTransfer(Money amount)
@Override
public Transfer makeTransfer(String counterAccount, Money amount)
throws BusinessException {
Transfer result = new Transfer(this, acct, amount);
Transfer result = super.makeTransfer(counterAccount, amount);
if (result.getCounterAccount().equals(this.registeredCounterAccount)) {
return result;
}
}


public void addInterest() {
Money interest = balance.multiply(INTEREST_PERCENTAGE);
if (interest.greaterThan(0)) {
balance.add(interest);
} else {
balance.substract(interest);
throw new BusinessException("Counter-account not registered!");
}
}
}
Expand Down

0 comments on commit 1fd61fb

Please sign in to comment.