fork download
  1. public class MoveRobot {
  2. public static void main(String[] args) {
  3. moveRobot(new Robot(Robot.Direction.UP, 5, 10), -2, 8);
  4. }
  5.  
  6. public static void moveRobot(Robot robot, int toX, int toY) {
  7. if (robot.getY() - toY < 0) { // moving robot to toY in Y
  8. switch (robot.getDirection()) { //making robot direction = UP
  9. case LEFT: robot.turnRight(); break;
  10. case RIGHT: robot.turnLeft(); break;
  11. case DOWN: robot.turnLeft(); robot.turnLeft(); break;
  12. }
  13. while (robot.getY() < toY){
  14. robot.stepForward();
  15. }
  16. }
  17. if (robot.getY() - toY > 0) {
  18. switch (robot.getDirection()) { //making robot direction = DOWN
  19. case LEFT: robot.turnLeft(); break;
  20. case RIGHT: robot.turnRight(); break;
  21. case UP: robot.turnLeft(); robot.turnLeft(); break;
  22. }
  23. while (robot.getY() > toY){
  24. robot.stepForward();
  25. }
  26. }
  27.  
  28. if (robot.getX() - toX < 0) { // moving robot to toX in X
  29. switch (robot.getDirection()) { //making robot direction = RIGHT
  30. case UP: robot.turnRight(); break;
  31. case DOWN: robot.turnLeft(); break;
  32. }
  33. while (robot.getX() < toX){
  34. robot.stepForward();
  35. }
  36. }
  37. if (robot.getY() - toX > 0) {
  38. switch (robot.getDirection()) { //making robot direction = LEFT
  39. case UP: robot.turnLeft(); break;
  40. case DOWN: robot.turnRight(); break;
  41. }
  42. while (robot.getX() > toX){
  43. robot.stepForward();
  44. }
  45. }
  46. }
  47.  
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class MoveRobot is public, should be declared in a file named MoveRobot.java
public class MoveRobot {
       ^
Main.java:6: error: cannot find symbol
    public static void moveRobot(Robot robot, int toX, int toY) {
                                 ^
  symbol:   class Robot
  location: class MoveRobot
Main.java:3: error: cannot find symbol
        moveRobot(new Robot(Robot.Direction.UP, 5, 10), -2, 8);
                      ^
  symbol:   class Robot
  location: class MoveRobot
Main.java:3: error: package Robot does not exist
        moveRobot(new Robot(Robot.Direction.UP, 5, 10), -2, 8);
                                 ^
Main.java:9: error: cannot find symbol
                case LEFT: robot.turnRight(); break;
                     ^
  symbol:   variable LEFT
  location: class MoveRobot
Main.java:10: error: cannot find symbol
                case RIGHT: robot.turnLeft(); break;
                     ^
  symbol:   variable RIGHT
  location: class MoveRobot
Main.java:11: error: cannot find symbol
                case DOWN: robot.turnLeft(); robot.turnLeft(); break;
                     ^
  symbol:   variable DOWN
  location: class MoveRobot
Main.java:19: error: cannot find symbol
                case LEFT: robot.turnLeft(); break;
                     ^
  symbol:   variable LEFT
  location: class MoveRobot
Main.java:20: error: cannot find symbol
                case RIGHT: robot.turnRight(); break;
                     ^
  symbol:   variable RIGHT
  location: class MoveRobot
Main.java:21: error: cannot find symbol
                case UP: robot.turnLeft(); robot.turnLeft(); break;
                     ^
  symbol:   variable UP
  location: class MoveRobot
Main.java:30: error: cannot find symbol
                case UP: robot.turnRight(); break;
                     ^
  symbol:   variable UP
  location: class MoveRobot
Main.java:31: error: cannot find symbol
                case DOWN: robot.turnLeft(); break;
                     ^
  symbol:   variable DOWN
  location: class MoveRobot
Main.java:39: error: cannot find symbol
                case UP: robot.turnLeft(); break;
                     ^
  symbol:   variable UP
  location: class MoveRobot
Main.java:40: error: cannot find symbol
                case DOWN: robot.turnRight(); break;
                     ^
  symbol:   variable DOWN
  location: class MoveRobot
14 errors
stdout
Standard output is empty