fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Orientation o = Orientation.WEST;
  13. System.out.println(o.turnLeft().turnRight().turnRight().turnRight()); // EAST
  14. System.out.println(o.turnRight().turnRight()); // EAST
  15. System.out.println(o.turnLeft()); // SOUTH
  16. }
  17.  
  18. static enum Orientation {
  19. NORTH, EAST, SOUTH, WEST;
  20.  
  21. public Orientation turnRight() {
  22. Orientation[] values = values();
  23. int ordinal = this.ordinal();
  24. if (ordinal == values.length - 1) {
  25. return NORTH;
  26. }
  27. return values[ordinal+ 1];
  28. }
  29.  
  30. public Orientation turnLeft() {
  31. Orientation[] values = values();
  32. int ordinal = this.ordinal();
  33. if (ordinal == 1) {
  34. return WEST;
  35. }
  36. return values[ordinal - 1];
  37. }
  38. }
  39. }
Success #stdin #stdout #stderr 0.05s 711168KB
stdin
Standard input is empty
stdout
EAST
EAST
SOUTH
stderr
Java HotSpot(TM) Client VM warning: No monotonic clock was available - timed services may be adversely affected if the time-of-day clock changes