Question: Implement the equals method of the Arrow class. Two arrows are equal when they have the same starting point and direction. Complete the following file:

Implement the equals method of the Arrow class. Two arrows are equal when they have the same starting point and direction.

Complete the following file:

Use the following code/ Please only modify and add code:

public class Arrow { private Point start; private String direction;

/** Constructs an arrow. @param x the x-position @param y the y-position @param direction a compass direction N E S W NE NW SE SW */ public Arrow(int x, int y, String direction) { start = new Point(); start.move(x, y); this.direction = direction; }

/** Checks whether this arrow is equal to another. @param otherObject another arrow @return true if this arrow and otherObject have the same start and direction. */ public boolean equals(Object otherObject) { . . . } }

Refer to the following files as reference:

ArrowTester.java

public class ArrowTester { public static void main(String[] args) { Arrow arrow1 = new Arrow(1, 2, "SE"); Object arrow2 = new Arrow(1, 2, "W"); Arrow arrow3 = new Arrow(1, 0, "SE"); Arrow arrow4 = new Arrow(0, 2, "SE"); Arrow arrow5 = new Arrow(1, 2, "SEE".substring(0, 2)); System.out.println(arrow1.equals(arrow1)); System.out.println("Expected: true"); System.out.println(arrow1.equals(arrow2)); System.out.println("Expected: false"); System.out.println(arrow1.equals(arrow3)); System.out.println("Expected: false"); System.out.println(arrow1.equals(arrow4)); System.out.println("Expected: false"); System.out.println(arrow1.equals(arrow5)); System.out.println("Expected: true"); } } 

Point.java

public class Point { private int x; private int y; /** Constructs a point at the origin. */ public Point() { this.x = 0; this.y = 0; } /** Moves this point by a given amount. @param dx the x-distance @param dy the y-distance */ public void move(int dx, int dy) { x = x + dx; y = y + dy; } /** Checks whether this point is equal to another. @param otherObject another point @return true if this point and otherObject have the same position. */ public boolean equals(Object otherObject) { Point other = (Point) otherObject; return x == other.x && y == other.y; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the equals method of the Arrow class so that it correctly compares two Arrow objects you can follow these steps Step 1 Check if the given ... View full answer

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!