Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
java_composition_over_inheritance/BankAccountComp.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
61 lines (53 sloc)
1.53 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BankAccountComp { | |
private InterestAccount acct; | |
private int accountAge; | |
//Constructors | |
public BankAccountComp () { | |
this.acct = new InterestAccount(0, 0.06); | |
this.accountAge = 0; | |
} | |
public BankAccountComp (double startingBal) { | |
this.acct = new InterestAccount(startingBal, 0.06); | |
this.accountAge = 0; | |
} | |
//Getters and Setters | |
public int getAccountAge () { return this.accountAge; } | |
public void setAccountAge (int a) { this.accountAge = a; } | |
public double getBalance () { return acct.getBalance(); } | |
//Other member functions | |
/** | |
* Given a double, add that amount to the balance | |
* @param sum The amount of money being deposited into the account | |
* @return The balance after the deposit | |
*/ | |
public double deposit (double sum) { | |
acct.setBalance(acct.getBalance() + sum); | |
return acct.getBalance(); | |
} | |
/** | |
* Given a double, add that ammount to the balance | |
* @param sum The amount of money being withdrawn from the account | |
* @return The balance after the withdrawal | |
*/ | |
public double withdraw (double sum) { | |
acct.setBalance(acct.getBalance() - sum); | |
return acct.getBalance(); | |
} | |
/** | |
* Accrue account for one year | |
* @return The balance of the account after accrual | |
*/ | |
public double accrue () { | |
accountAge++; | |
return acct.accrue(); | |
} | |
/** | |
* Given a number of years, accrue account over years | |
* @param y The number of years to accrue over | |
* @return The balance of the account after accrual | |
*/ | |
public double accrueYears (int y) { | |
accountAge += y; | |
return acct.accrueYears(y); | |
} | |
} |