Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.kotoday.experiment.bank;
- public class BankAccount {
- private double balance=0.0, interest=0.0, charges=0.0;
- private int deposits=0, withdrawals=0;
- BankAccount(double balance, double interest, double charges, int deposits, int withdrawls) {
- this.balance = balance;
- this.interest = interest;
- this.charges = charges;
- this.deposits = deposits;
- this.withdrawals = withdrawls;
- }
- protected void deposit(Double amount) {
- this.balance += amount;
- this.deposits++;
- }
- protected void withdrawal(Double amount) {
- this.balance -= amount;
- this.withdrawals ++;
- }
- protected void calcInterest() {
- double monthlyInterest = this.balance * (this.interest/12);
- this.balance += monthlyInterest;
- }
- public void monthlyProcess() {
- this.calcInterest();
- this.withdrawals = 0;
- this.charges = 0.0;
- this.deposits = 0;
- }
- void addServiceCharge(double amount) {
- this.charges += amount;
- }
- double getBalance() {
- return this.balance-this.charges;
- }
- int getWithdrawals() {
- return this.withdrawals;
- }
- public int getDeposits() {
- return this.deposits;
- }
- }
- package org.kotoday.experiment.bank;
- public class SavingsAccount extends BankAccount {
- private boolean active = true;
- SavingsAccount(double balance, double interest, double charges, int deposits, int withdrawls) {
- super(balance, interest, charges, deposits, withdrawls);
- }
- @Override
- public void withdrawal(Double amount) {
- if (this.active) {
- super.withdrawal(amount);
- checkActivity();
- }
- }
- @Override
- public void deposit(Double amount) {
- super.deposit(amount);
- checkActivity();
- }
- @Override
- public void monthlyProcess() {
- if (this.getWithdrawals() > 4) {
- this.addServiceCharge(this.getWithdrawals());
- this.checkActivity();
- }
- super.monthlyProcess();
- }
- private void checkActivity() {
- this.active = !(this.getBalance() < 25.0);
- }
- }
- package org.kotoday.experiment.bank;
- public class Driver {
- public static void main(String[] args) {
- SavingsAccount account = new SavingsAccount(1000,0.125, 0,0 ,0);
- account.deposit(35.0);
- account.monthlyProcess();
- System.out.print(account.getBalance());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement