SHARE
TWEET

Untitled

advictoriam Mar 5th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top