Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CheckingAccountTester2
- {
- public static void main (String[] args)
- {
- CheckingAccount bobsAccount = new CheckingAccount ("999", "Bob", 100);
- System.out.println (bobsAccount.getBalance ());
- bobsAccount.processDeposit (200);
- //This method can access the balance variable and add 200
- //bobsAccount.balance = bobsAccount.balance + 200 wont work
- System.out.println (bobsAccount.getBalance ());
- }
- }
- class CheckingAccount
- {
- private String accountNumber; //Variable Declarations
- private String accountHolder;
- private int balance;
- CheckingAccount (String accNumber, String holder, int start) //Constructor
- {
- accountNumber = accNumber;
- accountHolder = holder;
- balance = start;
- }
- double getBalance () //Returns the balance (duh)
- {
- return balance;
- }
- void processDeposit (double amount)
- {
- balance = balance + amount; //Note how nothing is returned
- }
- void processCheck (double amount)
- {
- double charge;
- if (balance < 1000)
- charge = .15;
- else
- charge = 0;
- balance = balance - amount - charge;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement