fork(1) download
  1. public class Robot {
  2.  
  3. private int x = 0;
  4. private int y = 0;
  5. private Direction direction = Direction.UP;
  6.  
  7. public Robot(Direction direction, int x, int y){
  8. this.direction = direction;
  9. this.x = x;
  10. this.y = y;
  11. }
  12.  
  13. public Direction getDirection() {
  14. return direction;
  15. }
  16.  
  17. public int getX() {
  18. // текущая координата X
  19. return x;
  20. }
  21.  
  22. public int getY() {
  23. // текущая координата Y
  24. return y;
  25. }
  26.  
  27. public void turnLeft() {
  28. // повернуться на 90 градусов против часовой стрелки
  29. switch (direction) {
  30. case UP:
  31. direction = Direction.LEFT;
  32. break;
  33. case LEFT:
  34. direction = Direction.DOWN;
  35. break;
  36. case DOWN:
  37. direction = Direction.RIGHT;
  38. break;
  39. case RIGHT:
  40. direction = Direction.UP;
  41. break;
  42. }
  43. System.out.println("Direction: "+direction);
  44. }
  45.  
  46. public void turnRight() {
  47. // повернуться на 90 градусов по часовой стрелке
  48. switch (direction) {
  49. case UP:
  50. direction = Direction.RIGHT;
  51. break;
  52. case LEFT:
  53. direction = Direction.UP;
  54. break;
  55. case DOWN:
  56. direction = Direction.LEFT;
  57. break;
  58. case RIGHT:
  59. direction = Direction.DOWN;
  60. break;
  61. }
  62. System.out.println("Direction: "+direction);
  63. }
  64.  
  65. public void stepForward() {
  66. // шаг в направлении взгляда
  67. // за один шаг робот изменяет одну свою координату на единицу
  68. switch (direction) {
  69. case UP:
  70. y++;
  71. break;
  72. case LEFT:
  73. x--;
  74. break;
  75. case DOWN:
  76. y--;
  77. break;
  78. case RIGHT:
  79. x++;
  80. break;
  81. }
  82. System.out.println("Moving in direction: "+direction);
  83. System.out.println("(x;y) = (" + x + ";" + y + ")");
  84. }
  85.  
  86. public enum Direction {
  87. UP,
  88. DOWN,
  89. LEFT,
  90. RIGHT
  91. }
  92.  
  93. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class Robot is public, should be declared in a file named Robot.java
public class Robot {
       ^
1 error
stdout
Standard output is empty