Commit 151b106

mo khan <mo@mokhan.ca>
2019-08-05 19:15:14
print full 10x10 grid
1 parent 3b7c58a
src/Q9/MovingRobot.java
@@ -47,18 +47,17 @@ public class MovingRobot extends Robot {
 
   public static String printGrid(Robot x, Robot y) {
     String grid = "";
-    int row = 0;
-
-    for (int column = 0; column < 10; column++) {
-      if (x.getX() == row && x.getY() == column) {
-        grid += "|X";
-      } else if (y.getX() == row && y.getY() == column) {
-        grid += "|Y";
-      } else {
-        grid += "| ";
+    for (int row = 0; row < 10; row++) {
+      for (int column = 0; column < 10; column++) {
+        if (x.getX() == row && x.getY() == column)
+          grid += "|X";
+        else if (y.getX() == row && y.getY() == column)
+          grid += "|Y";
+        else
+          grid += "| ";
       }
+      grid += "|\n";
     }
-    grid += "|\n";
 
     return grid;
   }
@@ -149,6 +148,7 @@ public class MovingRobot extends Robot {
   public static void main(String[] args) {
     MovingRobot r1 = new MovingRobot(0, 0);
     MovingRobot r2 = new MovingRobot(9, 9);
+
     while (!MovingRobot.sameSlot(r1, r2)) {
       r1.move();
       r2.move();
src/Q9/MovingRobotTest.java
@@ -148,7 +148,17 @@ public class MovingRobotTest extends TestCase {
     Robot r1 = new MovingRobot(0, 0);
     Robot r2 = new MovingRobot(9, 9);
 
-    String expected = "|X| | | | | | | | | |\n";
+    String expected =
+        "|X| | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | | |\n"
+            + "| | | | | | | | | |Y|\n";
     String result = MovingRobot.printGrid(r1, r2);
 
     System.out.println(expected);