Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- An account that earns interest at a fixed rate.
- */
- public class SavingsAccount extends BankAccount
- {
- private double interestRate;
- /**
- Constructs a bank account with a given interest rate.
- @balance initialBalance the initial balance
- @param rate the interest rate
- */
- public SavingsAccount(double initialBalance, double rate)
- {
- super(initialBalance);
- interestRate = rate;
- }
- /**
- Adds the earned interest to the account balance.
- */
- public void addInterest()
- {
- double interest = getBalance() * interestRate / 100;
- deposit(interest);
- }
- // This method checks your work. Do not modify it.
- public static double check(double initialBalance, double rate)
- {
- SavingsAccount account = new SavingsAccount(initialBalance, rate);
- account.addInterest();
- return account.getBalance();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement