Question: 1 . [ 6 marks] Point is a mutable data type. Re-write Point source code such that Point becomes an immutable data type. 2 .

 1. [6 marks] Point is a mutable data type. Re-write Point

1. [6 marks] Point is a mutable data type. Re-write Point source code such that Point becomes an immutable data type.

2. [6 marks] Override the Object contract by providing implementations for the methods toString, equals and hashCode. You must use the @Override annotation in the header of these methods.

  • toString()returns a string formatted as follows:

P(x_value, y_value)

  • equals() takes another Point object and returns a boolean value: true for equality and false for inequality.

  • hashCode() return a unique value based on the coordinates x and y.

3. [2 mark] Use standard Java annotation to document equals with the pre- and post-conditions.

4. [3 marks] Write a separate public class TestPoint and create three Point objects: p1(1,2), p2(2,3) and p3(1,2).

  • Test for equality of p1 and p3.

  • Print p2 to standard outpu

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 class Point { int x; int Y; public Point (int x, int y) { this.x = x; this.y = y; } public void setx(int x) { this.x = x; } public int getx() { return x; } public int getY() { return y; } public void setY(int y) { this.y = y; } } 21

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!