N
N
NikitaWeb2018-11-19 18:35:59
Java
NikitaWeb, 2018-11-19 18:35:59

Doesn't pass the test. What is the problem?

There is this code:

package net.thumbtack.school.windows.v1;

import java.util.Objects;

public class Point {

    private int x, y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Point() {
        Point zero = new Point(0,0);
    }

    public Point(Point point) {
        Point point1 = point;
    }

    public int getX() {
        return this.x;
    }

    public int getY() {
        return this.y;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void moveTo(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void moveRel(int dx, int dy) {
        this.x += dx;
        this.y += dy;
    }

    public boolean isVisibleOnDesktop(Desktop desktop) {
        if (x <= 0 || y <= 0) return false;
        if (x <= desktop.getWidth() && y <= desktop.getHeight()) return true;
        else return false;
    }

    public boolean isNotVisibleOnDesktop(Desktop desktop) {
        if (x <= 0 || y <= 0) return true;
        if (x <= desktop.getWidth() && y <= desktop.getHeight()) return false;
        else return true;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Point point = (Point) o;
        return x == point.x ||
                y == point.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}

It fails this test:
5bf2d844ed74e573391935.png
What should be the code to pass this test?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cheypnow, 2018-11-20
@NikitaWeb

one.

public Point(Point point) {
        this.x = point.x;
        this.y = point.y;
    }

2.
@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Point point = (Point) o;
        return x == point.x && y == point.y;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question