Advertisement
And1

Laba

Mar 14th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public class Test {
  2. public static void main(String[] args) {
  3. Queen a = new Queen('a', 1);
  4. Queen b = new Queen('b', 2);
  5. Desk d = new Desk(a, b);
  6. System.out.println(d);
  7. }
  8. }
  9.  
  10. //////////////////////////////////////////////////
  11.  
  12. public class Queen {
  13. private char x;
  14. private int y;
  15. public Queen (char x, int y){
  16. this.x=x;
  17. this.y=y;
  18. }
  19. public char getX(){
  20. return x;
  21. }
  22. public int getY(){
  23. return y;
  24. }
  25.  
  26. public String toString() {
  27. return x + " " + y;
  28. }
  29. }
  30.  
  31. /////////////////////////////////////////////////////////
  32.  
  33. public class Desk {
  34. private Queen x;
  35. private Queen y;
  36. public Desk (Queen x, Queen y){
  37. this.x=x;
  38. this.y=y;
  39. }
  40. public Queen getX(){
  41. return x;
  42. }
  43. public Queen getY(){
  44. return y;
  45. }
  46. public static boolean check(Queen a, Queen b){
  47. if (a.getX() == b.getX() ||
  48. a.getY() == b.getY() ||
  49. Math.abs((int)a.getX() - (int)b.getX()) == Math.abs(a.getY() - b.getY())) return true;
  50. else return false;
  51. }
  52. public String toString(){
  53. if (check(x, y)) return "Queen " + x + " beats queen " + y;
  54. else return "Queen " + x + " doesn't beat " + " queen " + y;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement