Domino.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Domino.java
  3. *
  4. * Contains the data structure for an individual domino
  5. *
  6. */
  7. import java.util.ArrayList;
  8. public class Domino
  9. {
  10. //fields
  11. private int leftSquare;
  12. private int rightSquare;
  13. //constructor takes two integers and creates a single domino
  14. public Domino(int leftInput, int rightInput)
  15. {
  16. setSquareValues(leftInput, rightInput);
  17. //System.out.println("Domino " + this + " created!");
  18. }
  19. // used by the contructor to set values of domino
  20. private void setSquareValues(int leftInput, int rightInput)
  21. {
  22. leftSquare = leftInput;
  23. rightSquare = rightInput;
  24. }
  25. //getter methods for left and right values of domino
  26. public int getLeftSquare()
  27. {
  28. return leftSquare;
  29. }
  30. public int getRightSquare()
  31. {
  32. return rightSquare;
  33. }
  34. //print this domino
  35. public String toString()
  36. {
  37. return "[" + leftSquare + "|" + rightSquare + "]";
  38. }
  39. //Rotates a domino in place.
  40. public static Domino rotateDomino(Domino d)
  41. {
  42. return new Domino(d.rightSquare, d.leftSquare);
  43. }
  44. }