Advertisement
Guest User

Untitled

a guest
May 29th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. class CheckingAccountTester2
  2. {
  3.     public static void main (String[] args)
  4.     {
  5.         CheckingAccount bobsAccount = new CheckingAccount ("999", "Bob", 100);
  6.         System.out.println (bobsAccount.getBalance ());
  7.         bobsAccount.processDeposit (200);
  8.         //This method can access the balance variable and add 200
  9.         //bobsAccount.balance = bobsAccount.balance + 200 wont work
  10.         System.out.println (bobsAccount.getBalance ());
  11.     }
  12. }
  13. class CheckingAccount
  14. {
  15.  
  16.     private String accountNumber; //Variable Declarations
  17.     private String accountHolder;
  18.     private int balance;
  19.     CheckingAccount (String accNumber, String holder, int start)  //Constructor
  20.     {
  21.         accountNumber = accNumber;
  22.         accountHolder = holder;
  23.         balance = start;
  24.     }
  25.  
  26.  
  27.     double getBalance ()  //Returns the balance (duh)
  28.     {
  29.         return balance;
  30.     }
  31.  
  32.  
  33.     void processDeposit (double amount)
  34.     {
  35.         balance = balance + amount; //Note how nothing is returned
  36.     }
  37.  
  38.  
  39.     void processCheck (double amount)
  40.     {
  41.         double charge;
  42.         if (balance < 1000)
  43.             charge = .15;
  44.         else
  45.             charge = 0;
  46.         balance = balance - amount - charge;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement