lots of exercises in java... from https://github.com/exercism/java

Direction.java 437B

123456789101112131415161718192021222324252627282930
  1. enum Direction {
  2. UP ( 0, -1),
  3. RIGHT( 1, 0),
  4. DOWN ( 0, 1),
  5. LEFT (-1, 0);
  6. private final int dx;
  7. private final int dy;
  8. Direction(int dx, int dy) {
  9. this.dx = dx;
  10. this.dy = dy;
  11. }
  12. int getDx() {
  13. return dx;
  14. }
  15. int getDy() {
  16. return dy;
  17. }
  18. Direction turnRight() {
  19. return Direction.values()[(ordinal() + 1) % Direction.values().length];
  20. }
  21. }