Advertisement
dmesticg

Untitled

Mar 28th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public class Position {
  2.  
  3. private int positionRow;
  4. private int positionColumn;
  5.  
  6. public Position(int row, int column) {
  7. positionColumn = column;
  8. positionRow = row;
  9. }
  10.  
  11. public int getRow() {
  12. return positionRow;
  13. }
  14.  
  15. public int getCol() {
  16. return positionColumn;
  17. }
  18.  
  19. public void setRow (int newRow) {
  20. positionRow = newRow;
  21. }
  22.  
  23. public void setCol (int newCol) {
  24. positionColumn = newCol;
  25. }
  26.  
  27.  
  28. public boolean equals (Position otherPosition) {
  29. if (otherPosition.getRow() == this.getRow() && otherPosition.getCol() == this.getCol() ) {
  30. return true;
  31. } else {
  32. return false;
  33. }
  34. }
  35.  
  36. public static void main (String[] args) {
  37. Position pos1 = new Position(1,2);
  38. Position pos2 = new Position(1,2);
  39. System.out.println(pos1.equals(pos2));
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement