diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-11 17:58:50 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-11 17:58:50 -0600 |
| commit | 81e51d1a04d6fbcbc4365a78975d383e35d04ac5 (patch) | |
| tree | 0673324025cfd821233c8900eea1390e8d150c07 /src | |
| parent | 03d8081a7382705a81ed2c80e2bc1e4f807b5dc6 (diff) | |
add documentation
Diffstat (limited to 'src')
| -rw-r--r-- | src/Q9/MovingRobot.java | 21 | ||||
| -rw-r--r-- | src/Q9/README.md | 20 | ||||
| -rw-r--r-- | src/Q9/Robot.java | 21 |
3 files changed, 33 insertions, 29 deletions
diff --git a/src/Q9/MovingRobot.java b/src/Q9/MovingRobot.java index 21c46a1..8c20ec8 100644 --- a/src/Q9/MovingRobot.java +++ b/src/Q9/MovingRobot.java @@ -54,32 +54,24 @@ public class MovingRobot extends Robot { } } - /** - * @return a random direction. - */ + /** @return a random direction. */ public int generateNextMove() { return this.rng.nextInt(7) + 1; } - /** - * @return true if the two robots are in the same coordinate. - */ + /** @return true if the two robots are in the same coordinate. */ public static boolean sameSlot(Robot r1, Robot r2) { return r1.getX() == r2.getX() && r1.getY() == r2.getY(); } - /** - * @return The list of moves made by the robot. - */ + /** @return The list of moves made by the robot. */ public String printMoves() { ArrayList<String> printableMoves = new ArrayList<String>(); for (Integer move : this.moves) printableMoves.add(String.valueOf(move)); return String.join(",", printableMoves); } - /** - * Moves the robot in a random direction. - */ + /** Moves the robot in a random direction. */ public void move() { int direction = generateNextMove(); while (!validateNextMove(direction)) direction = generateNextMove(); @@ -87,8 +79,8 @@ public class MovingRobot extends Robot { } /** - * An overload of the move method that attempts to move in the direction - * specified. + * An overload of the move method that attempts to move in the direction specified. + * * @param direction the direction to move the robot towards. */ public void move(int direction) { @@ -163,6 +155,7 @@ public class MovingRobot extends Robot { /** * The entry point to the console application. + * * @param args the argument vector provided to the program. */ public static void main(String[] args) { diff --git a/src/Q9/README.md b/src/Q9/README.md index b6a8a1f..766de90 100644 --- a/src/Q9/README.md +++ b/src/Q9/README.md @@ -56,6 +56,26 @@ Implement this program with a `Robot` class and a `MovingRobot` subclass. 1. Description of the Code + + The program includes a `Robot` class and a `MovingRobot` class that inherits + from Robot. Before the `MovingRobot` can advance to the next position based on + a direction, it will check to see if it is possible to advance without hitting + the bounds of the 9x9 grid. + 1. Errors and Warnings + + This program does not require input from a user. + This program depends on a random number generator to randomly generate the + direction to move the robot towards. This program attempts to check the grid + boundaries before advancing to the next position. + 1. Sample Input and Output + + ```bash + ```` + 1. Discussion + +This was fun. Instead of passing around x and y coordinate, I would have +preferred to extract a `Coordinate` class that can check the boundaries of the +grid. diff --git a/src/Q9/Robot.java b/src/Q9/Robot.java index 787f7cc..ee495e6 100644 --- a/src/Q9/Robot.java +++ b/src/Q9/Robot.java @@ -37,6 +37,7 @@ public class Robot { /** * Constructs an instance of a robot. + * * @param x the x coordinate of the robot. * @param y the y coordinate of the robot. */ @@ -45,37 +46,27 @@ public class Robot { this.y = y; } - /** - * @return the x coordinate - */ + /** @return the x coordinate */ public int getX() { return x; } - /** - * @return the y coordinate - */ + /** @return the y coordinate */ public int getY() { return y; } - /** - * @param x the x coordinate to move to. - */ + /** @param x the x coordinate to move to. */ public void setX(int x) { this.x = x; } - /** - * @param y the y coordinate to move to. - */ + /** @param y the y coordinate to move to. */ public void setY(int y) { this.y = y; } - /** - * @return true if the robot is at the given coordinate - */ + /** @return true if the robot is at the given coordinate */ public boolean atPosition(int x, int y) { return getX() == x && getY() == y; } |
