Advertisement
MattPlummer

exercise 3.4

Oct 1st, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. public class BankAccount {
  2.  
  3.     public static void main(String[] args) {}
  4.         private double balance;
  5.        
  6.         public BankAccount()
  7.         {
  8.         balance = 0;
  9.         }
  10.         public BankAccount(double initialBalance)
  11.         {
  12.         balance = initialBalance;
  13.         }
  14.         public void deposit(double amount)
  15.         {
  16.         double newBalance = balance + amount;
  17.         balance = newBalance;
  18.         }
  19.         public void withdraw(double amount)
  20.         {
  21.         double newBalance = balance - amount;
  22.         balance = newBalance;
  23.         }
  24.         public double getBalance()
  25.         {
  26.         return balance;
  27.         }
  28.         public double addInterest(double rate)
  29.         {
  30.         balance = balance * rate + balance;
  31.         return balance;
  32.         }
  33.         }
  34.  
  35.  
  36. public class BankAccountTester
  37. {
  38. public static void main(String[] args)
  39. {
  40. BankAccount momsSavings = new BankAccount(1000);
  41. System.out.println("old Balance: " +momsSavings.getBalance());// getBalance
  42. momsSavings.addInterest(.1);
  43.  
  44. System.out.println("new Balance: " +momsSavings.getBalance());// getBalance
  45. System.out.println(momsSavings);
  46. System.out.println("Expected:1120");
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement