How to find x and y values of Point objects?

Hi, I'm writing a class Rectangle that has private int x, y, width, height, and Point p1. I need to change just the Point's x and y values.

I'm having trouble getting the x and y values of a Point p. I brought in the Point p from main, so I'm getting the error: x has private access in Point.

Is this because I didn't initialize p in the constructor itself?

I would really appreciate any help!

This is my constructor below:

Code:

public Rectangle(Point p, int width, int height)

{

this.p1 = p;

this.x = p.x;

this.y = p.y;

this.width = width;

this.height = height;

}

Re: How to find x and y values of Point objects?

In my version of the JSE classes the Point class has public members x and y ... are you using your own Point class?

kind regards,

Jos

Re: How to find x and y values of Point objects?

Yes, I am using my own Point class. Even when I import the java.awt package, I still can't do ( this.x = p.x; )

Re: How to find x and y values of Point objects?

If it's your own Point class, then write a setX() method for it that's public. And use that method to change the value.

Re: How to find x and y values of Point objects?

Thanks, but how should I call that in my Rectangle constructor?

Re: How to find x and y values of Point objects?

You would call the setter methods whereever you want to set the values.

-----

You said you wanted to set a point's values. But you also said your rectangle also has x and y values. Are you sure you don't want to **get** the point's values and assign them to x and y of the rectangle? The process is the same: write getter methods for the point class and use them wherever you like - including in the rectangle constructor if that makes sense.

Re: How to find x and y values of Point objects?

Thank you so much! I finally got everything after three hours of confusion. Thanks a bunch.

Re: How to find x and y values of Point objects?