Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void main(String[] args) {
- Queen a = new Queen('a', 1);
- Queen b = new Queen('b', 2);
- Desk d = new Desk(a, b);
- System.out.println(d);
- }
- }
- //////////////////////////////////////////////////
- public class Queen {
- private char x;
- private int y;
- public Queen (char x, int y){
- this.x=x;
- this.y=y;
- }
- public char getX(){
- return x;
- }
- public int getY(){
- return y;
- }
- public String toString() {
- return x + " " + y;
- }
- }
- /////////////////////////////////////////////////////////
- public class Desk {
- private Queen x;
- private Queen y;
- public Desk (Queen x, Queen y){
- this.x=x;
- this.y=y;
- }
- public Queen getX(){
- return x;
- }
- public Queen getY(){
- return y;
- }
- public static boolean check(Queen a, Queen b){
- if (a.getX() == b.getX() ||
- a.getY() == b.getY() ||
- Math.abs((int)a.getX() - (int)b.getX()) == Math.abs(a.getY() - b.getY())) return true;
- else return false;
- }
- public String toString(){
- if (check(x, y)) return "Queen " + x + " beats queen " + y;
- else return "Queen " + x + " doesn't beat " + " queen " + y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement