Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. public interface Account {
  2.    
  3.     public void deposit(int amount);
  4.    
  5.     public boolean withdraw(int amount);
  6.    
  7.     public int getBalance();
  8.    
  9.     public void yearEnd();
  10.    
  11. }
  12.  
  13. public abstract class AbstractAccount implements Account {
  14.     private int money;
  15.    
  16.     public void deposit(int amount) {
  17.         if(amount < 0) {
  18.             throw new IllegalArgumentException();
  19.         }
  20.         this.money += amount;
  21.     }
  22.    
  23.     public int getBalance() {
  24.         return this.money;
  25.     }
  26.    
  27.     public abstract boolean withdraw(int amount);
  28.    
  29.     public abstract void yearEnd();
  30. }
  31.  
  32. public class AccountWithInterest extends AbstractAccount {
  33.    
  34.     public AccountWithInterest() {
  35.         this.money = 0;
  36.     }
  37.    
  38.     public boolean withdraw(int amount) {
  39.         if(amount < 0) {
  40.             throw new IllegalArgumentException();
  41.         } else if(this.money >= amount) {
  42.             this.money -= amount;
  43.             return true;
  44.         }
  45.         return false;
  46.     }
  47.    
  48.     public void yearEnd() {
  49.         this.money = this.money + (this.money()*5)/100;
  50.     }
  51. }
  52.  
  53.  
  54. public class FeeBasedAccount extends AbstractAccount {
  55.    
  56.     private int transactions;
  57.    
  58.     public FeeBasedAccount() {
  59.         this.money = 0;
  60.         this.transactions = 0;
  61.     }
  62.    
  63.     public boolean withdraw(int amount) {
  64.         if(amount < 0) {
  65.             throw new IllegalArgumentException();
  66.         }
  67.         this.money -= amount;
  68.         this.transactions += 1;
  69.         return true;
  70.     }
  71.    
  72.     public void yearEnd() {
  73.         this.money -= transactions;
  74.         this.transactions = 0;
  75.     }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement