Question: JAVA: Implement the toString method of the following version of the Arrow class. Return strings such as (1, 2) SE public class Arrow { private

JAVA: Implement the toString method of the following version of the Arrow class. Return strings such as (1, 2) SE

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; }

/** Gets a string representation of this arrow. @return the string representation such as (1, 2) NW */ public String toString() { . . . } }

Here are the test files for reference:

ArrowTester.java

public class ArrowTester { public static void main(String[] args) { Arrow arrow1 = new Arrow(1, 2, "SE"); System.out.println(arrow1); System.out.println("Expected: (1, 2) SE"); Arrow arrow2 = new Arrow(-1, 0, "W"); System.out.println(arrow2); System.out.println("Expected: (-1, 0) W"); } } 

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; } /** Gets a string representation of this point. */ public String toString() { return "(" + x + ", " + y + ")"; } } 

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!