Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package accounts;
- public class SavingsAccount extends BankAccount
- {
- private int mInterestRate;
- public SavingsAccount(int id, String name) { super(id, name); }
- public SavingsAccount(int id, String name, int balance) { super(id, name, balance); }
- public int getInterestRate() { return mInterestRate; }
- public void setInterestRate(int newInterestRate) { mInterestRate = newInterestRate; }
- public void applyInterest()
- {
- float interest = mInterestRate / 100f * mBalance;
- mBalance += interest;
- }
- @Override public void deposit(int amount)
- {
- if (amount < 0)
- throw new IllegalArgumentException("The amount can not be smaller than 0.");
- if (amount > 10_000)
- throw new IllegalArgumentException("The amount can not be greater than 10_000 in a SavingsAccount.");
- mBalance += amount;
- }
- /** @return Json string representation of the class. */
- @Override public String toString()
- {
- return new StringBuilder()
- .append("{ \"type\": \"SavingsAccount\"" )
- .append(", \"id\": " )
- .append(getId() )
- .append(", \"accountHolder\": \"" )
- .append(getName() )
- .append("\", \"currentBalance\": " )
- .append(mBalance )
- .append(", \"interestRate\": " )
- .append(mInterestRate )
- .append(" }" )
- .toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement