Designing classes
The this operator
Make sure you read thoroughly.
1. Make the following changes to the BankAccount class:
a. Include a print statement in the getBalance() method to show the reference to the implicit parameter. Include “from method getBalance”
b. Include a print statement in both constructors, “from method default constructor” and “from constructor with parameter”.
2. Implement a test class, ThisOperatorTest. In this test, create an object of the class BankAccount and print it.
3. Include a commented paragraph at the end of the test class making a conclusion on the output. Make sure you explain what the this operator does in the two programs and compare them.
4. The following questions refer to calling by reference, by value and side effects:
• Modify your BankAccount class to include a new method, transfer. This method has two input parameters, double amount and double otherBalance from a different BankAccount object. The method takes money from the calling object’s balance and increases the balance from the other object by the “amount” value. The method also includes two print statements to display each object.
System.out.println(“From transfer( ), current object @: ” + _missing parameter);
System.out.println(“From transfer( ), otherAccount @: ” + otherBalance);
Create a test class, BankAccountTest1. In main:
• Create two BankAccount objects.
• Display the balance from both objects.
• Call the transfer method from one object to transfer money to the other object’s balance.
• Display both accounts’ balance.
A different approach to the same idea in 4:
• Modify your BankAccount class to include a new method, transfer. This method has two input parameters, double amount and BankAccount otherAccount. The method takes money from the calling object’s balance and increases the otherAccount’s balance by the “amount” value. The method also includes two print statements to display each object.
System.out.println(“From transfer( ), current object @: ” + _missing parameter);
System.out.println(“From transfer( ), otherAccount @: ” + otherAccount);
Look at edmodo.com for the different posts and due dates.