Commit 81e51d1

mo khan <mo@mokhan.ca>
2019-08-11 23:58:50
add documentation
1 parent 03d8081
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) {
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.
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;
   }