Commit 8f840e9

mo khan <mo@mokhan.ca>
2019-08-05 20:02:20
extract method atPosition
1 parent 2394801
Changed files (1)
src/Q9/Robot.java
@@ -43,12 +43,16 @@ public class Robot {
     this.y = y;
   }
 
+  public boolean atPosition(int x, int y) {
+    return getX() == x && getY() == y;
+  }
+
   public static String printGrid(Robot r1, Robot r2) {
     String grid = "";
     for (int row = 0; row < 10; row++) {
       for (int column = 0; column < 10; column++) {
-        if (r1.getX() == row && r1.getY() == column) grid += "|1";
-        else if (r2.getX() == row && r2.getY() == column) grid += "|2";
+        if (r1.atPosition(row, column)) grid += "|1";
+        else if (r2.atPosition(row, column)) grid += "|2";
         else grid += "| ";
       }
       grid += String.format("|%s", System.lineSeparator());