Advertisement
advictoriam

Untitled

Mar 5th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. /**
  2.    An account that earns interest at a fixed rate.
  3. */
  4. public class SavingsAccount extends BankAccount
  5. {  
  6.    private double interestRate;
  7.  
  8.    /**
  9.       Constructs a bank account with a given interest rate.
  10.       @balance initialBalance the initial balance
  11.       @param rate the interest rate
  12.    */
  13.    public SavingsAccount(double initialBalance, double rate)
  14.    {  
  15.       super(initialBalance);
  16.       interestRate = rate;
  17.    }
  18.  
  19.    /**
  20.       Adds the earned interest to the account balance.
  21.    */
  22.    public void addInterest()
  23.    {  
  24.       double interest = getBalance() * interestRate / 100;
  25.       deposit(interest);
  26.    }
  27.  
  28.    // This method checks your work.  Do not modify it.
  29.    
  30.    public static double check(double initialBalance, double rate)
  31.    {
  32.       SavingsAccount account = new SavingsAccount(initialBalance, rate);
  33.       account.addInterest();
  34.       return account.getBalance();
  35.    }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement