-1

This is the question being asked attached as a picture

And the code I typed for it is given below:

class MyPoint {
    public int x;
    public int y;

    public MyPoint(){
        x = 0;
        y = 0;
    }

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

    public void setXY(int newx, int newy) {
        x = newx;
        y = newy;
    }
    public int[] getXY() {
        int [] getXYarray = new int[2];
        getXYarray[0] = x;
        getXYarray[1] = y;
        return getXYarray;
    }
    public String toString() {
        return "(" + x + "," + y + ")";
    }

But i cannot see what is actually wrong here. The java compiler gives me this error Please tell me where i am going wrong with this as i am very lost.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54

2 Answers2

1

The test code tries to use the methods getX() and getY(). You do not define those methods, you only define getXY().

(Please provide textual information as text in the future, it would have made answering this easier for me.)

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
1

The third bullet point from the bottom says you need "Getter and setter for the instance variables x and y". Implement those and I suspect your Tester will pass.

public int getX() {
    return x;
}
public void setX(int x) {
    this.x = x;
}
public int getY() {
    return y;
}
public void setY(int y) {
    this.y = y;
}

Your instructions also call for an overloaded constructor that takes a MyPoint (a copy constructor)

public MyPoint(MyPoint that) {
    this.x = that.x;
    this.y = that.y;
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249