summaryrefslogtreecommitdiff
path: root/src/Q9
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2019-08-05 13:15:14 -0600
committermo khan <mo@mokhan.ca>2019-08-05 13:15:14 -0600
commit151b106f5d265f17ccf38e978c197e1e38dc4deb (patch)
treea3ef81ee204ef9015990b39c9712abdb0372c2d0 /src/Q9
parent3b7c58abefca9db8b1b3431e308fccbe5eeab1e9 (diff)
print full 10x10 grid
Diffstat (limited to 'src/Q9')
-rw-r--r--src/Q9/MovingRobot.java20
-rw-r--r--src/Q9/MovingRobotTest.java12
2 files changed, 21 insertions, 11 deletions
diff --git a/src/Q9/MovingRobot.java b/src/Q9/MovingRobot.java
index 391f407..3cbccaa 100644
--- a/src/Q9/MovingRobot.java
+++ b/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();
diff --git a/src/Q9/MovingRobotTest.java b/src/Q9/MovingRobotTest.java
index dbc5671..a91c984 100644
--- a/src/Q9/MovingRobotTest.java
+++ b/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);