Advertisement
JoshJurban

Exercise 3.4

Oct 7th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package bankaccounttester;
  2.  
  3. public class BankAccount
  4. {
  5.         private double balance;
  6.        
  7.         public BankAccount()
  8.         {
  9.                 balance = 0;
  10.         }
  11.         /**
  12.          * Constructs a bank account with a given balance
  13.          * @param initialBalance the initial balance
  14.          */
  15.         public BankAccount(double initialBalance)
  16.         {
  17.                 balance = initialBalance;
  18.         }
  19.         /**
  20.          * Deposits money into the bank account
  21.          * @param amount the amount to deposit
  22.          */
  23.         public void deposit(double amount)
  24.         {
  25.                 balance = balance + amount;
  26.         }
  27.         /**
  28.          * Withdraws money from the bank account
  29.          * @param amount the amount to withdraw
  30.          */
  31.         public void withdraw(double amount)
  32.         {
  33.                 balance = balance - amount;
  34.         }
  35.         /**
  36.          * Gets the current balance of the bank account.
  37.          * @return the current balance
  38.          */
  39.         public double getBalance()
  40.         {
  41.                 return balance;
  42.         }      
  43.         /**
  44.          * Adds interest to the current balance of the account.
  45.          * @param rate
  46.          */
  47.         public void addInterest(double rate)
  48.         {
  49.                 balance = balance *(1+rate);
  50.         }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement