O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Requirement – starting point and orientation

We need to know what the current location of the ship is in order to be able to move it. Moreover, we should also know which direction it is facing: north, south, east, or west. Therefore, the first requirement is the following:

You are given the initial starting point (x, y) of a ship and the direction (N, S, E, or W) it is facing.

Before we start working on this requirement, let's go through the helper classes that can be used. The Point class holds the x and y coordinates. It has the following constructor:

public Point(int x, int y) {
  this.x = x;
  this.y = y;
}

Similarly, we have the Direction enum class with the following values:

public enum Direction { NORTH(0, 'N), EAST(1, 'E'), SOUTH(2, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required