Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface Account {
- public void deposit(int amount);
- public boolean withdraw(int amount);
- public int getBalance();
- public void yearEnd();
- }
- public abstract class AbstractAccount implements Account {
- private int money;
- public void deposit(int amount) {
- if(amount < 0) {
- throw new IllegalArgumentException();
- }
- this.money += amount;
- }
- public int getBalance() {
- return this.money;
- }
- public abstract boolean withdraw(int amount);
- public abstract void yearEnd();
- }
- public class AccountWithInterest extends AbstractAccount {
- public AccountWithInterest() {
- this.money = 0;
- }
- public boolean withdraw(int amount) {
- if(amount < 0) {
- throw new IllegalArgumentException();
- } else if(this.money >= amount) {
- this.money -= amount;
- return true;
- }
- return false;
- }
- public void yearEnd() {
- this.money = this.money + (this.money()*5)/100;
- }
- }
- public class FeeBasedAccount extends AbstractAccount {
- private int transactions;
- public FeeBasedAccount() {
- this.money = 0;
- this.transactions = 0;
- }
- public boolean withdraw(int amount) {
- if(amount < 0) {
- throw new IllegalArgumentException();
- }
- this.money -= amount;
- this.transactions += 1;
- return true;
- }
- public void yearEnd() {
- this.money -= transactions;
- this.transactions = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement