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

123456789101112131415161718192021222324252627282930313233343536373839
  1. final class Queen {
  2. private final int row;
  3. private final int column;
  4. Queen(final int row, final int column) {
  5. this.row = row;
  6. this.column = column;
  7. validatePosition();
  8. }
  9. int getRow() {
  10. return row;
  11. }
  12. int getColumn() {
  13. return column;
  14. }
  15. private void validatePosition() {
  16. validatePositionComponent(row, "row");
  17. validatePositionComponent(column, "column");
  18. }
  19. private void validatePositionComponent(final int value, final String componentName) {
  20. if (value < 0) {
  21. throw new IllegalArgumentException("Queen position must have positive " + componentName + ".");
  22. }
  23. if (value > 7) {
  24. throw new IllegalArgumentException("Queen position must have " + componentName + " <= 7.");
  25. }
  26. }
  27. }