Part #1: Practice with Equals method Read the discussion on the equals() method
ID: 3568932 • Letter: P
Question
Part #1: Practice with Equals method
Read the discussion on the equals() method in section 9.8. Create a BlueJ project with two classes: a Test class and a Control class. The Test class will consist of two fields: an int and a String. You will use the Control class to run tests against the Test class.
Following the example in section 9.8 you will override the equals() method inherited from the Object superclass and write your own. You should perform the same types of checks (i.e. self-reference, instanceof and field by field comparison).
Create a Display() method in the Control class that creates three instances of the Test class. Two of the three instances will be equal (content equality) and the third will be different (i.e. at least one of the fields will be different).
You will also need to test all three parts of the equals() method. So add four lines to the end of the Display() method, each one will test one aspect of the equals method. For example:
System.out.println("t1 equals t1: " + t1.equals(t1)); // same object
Explanation / Answer
/// :)