SHARE
TWEET

Untitled

a guest Feb 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.kotoday.experiment.bank;
  2.  
  3. public class BankAccount {
  4.     private double balance=0.0, interest=0.0, charges=0.0;
  5.     private int deposits=0, withdrawals=0;
  6.  
  7.     BankAccount(double balance, double interest, double charges, int deposits, int withdrawls) {
  8.         this.balance = balance;
  9.         this.interest = interest;
  10.         this.charges = charges;
  11.         this.deposits = deposits;
  12.         this.withdrawals = withdrawls;
  13.     }
  14.  
  15.     protected void deposit(Double amount) {
  16.         this.balance += amount;
  17.         this.deposits++;
  18.     }
  19.     protected void withdrawal(Double amount) {
  20.         this.balance -= amount;
  21.         this.withdrawals ++;
  22.     }
  23.  
  24.     protected void calcInterest() {
  25.         double monthlyInterest = this.balance * (this.interest/12);
  26.         this.balance += monthlyInterest;
  27.     }
  28.  
  29.     public void monthlyProcess() {
  30.         this.calcInterest();
  31.         this.withdrawals = 0;
  32.         this.charges = 0.0;
  33.         this.deposits = 0;
  34.     }
  35.  
  36.     void addServiceCharge(double amount) {
  37.         this.charges += amount;
  38.     }
  39.  
  40.     double getBalance() {
  41.         return this.balance-this.charges;
  42.     }
  43.  
  44.     int getWithdrawals() {
  45.         return this.withdrawals;
  46.     }
  47.  
  48.     public int getDeposits() {
  49.         return this.deposits;
  50.     }
  51. }
  52.  
  53. package org.kotoday.experiment.bank;
  54.  
  55. public class SavingsAccount extends BankAccount {
  56.     private boolean active = true;
  57.  
  58.     SavingsAccount(double balance, double interest, double charges, int deposits, int withdrawls) {
  59.         super(balance, interest, charges, deposits, withdrawls);
  60.     }
  61.     @Override
  62.     public void withdrawal(Double amount) {
  63.         if (this.active) {
  64.             super.withdrawal(amount);
  65.             checkActivity();
  66.         }
  67.     }
  68.  
  69.     @Override
  70.     public void deposit(Double amount) {
  71.         super.deposit(amount);
  72.         checkActivity();
  73.     }
  74.  
  75.     @Override
  76.     public void monthlyProcess() {
  77.         if (this.getWithdrawals() > 4) {
  78.             this.addServiceCharge(this.getWithdrawals());
  79.             this.checkActivity();
  80.         }
  81.         super.monthlyProcess();
  82.     }
  83.  
  84.     private void checkActivity() {
  85.         this.active = !(this.getBalance() < 25.0);
  86.     }
  87. }
  88.  
  89. package org.kotoday.experiment.bank;
  90.  
  91. public class Driver {
  92.     public static void main(String[] args) {
  93.         SavingsAccount account = new SavingsAccount(1000,0.125, 0,0 ,0);
  94.         account.deposit(35.0);
  95.         account.monthlyProcess();
  96.         System.out.print(account.getBalance());
  97.     }
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top