Loading...
Loading...
Loading...
A drawing app checks whether two taps hit the same point. Write a class Point (x, y) with a correct equals() and hashCode(). For each pair of points, print SAME when they are equal, else DIFFERENT. Finally print how many pairs were the same.
SAME or DIFFERENT for each pair, then Same pairs: <count>.Example
Input
3 1 2 1 2 1 2 2 1 -5 0 -5 0
Output
SAME DIFFERENT SAME Same pairs: 2
(1, 2) and (2, 1) have the same numbers in a different order, so they differ.
Try the problem first. Open one hint at a time.
Two new Point(...) objects are never ==; compare x and y inside equals().
Follow the recipe: same reference, null, getClass(), cast, compare fields.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor