I need to create a Point and Rectangle class for a homework assignment and I'm unsure if I have the right idea with what im trying to do. In my Point class it much have a accesor and mutator, and also a distance method which is what im haveing trouble with.
public class Point {
private int x;
private int y;
public Point ( int x, int y ){
this.x = x;
this.y = y;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
// not sure if this will work yet
public double distance ( Point otherPoint)
{
double dx = getX() - otherPoint.getX();
double dy = getY() - otherPoint.getY();
double dist = Math.sqrt(dx*dx + dy*dy);
return dist;
}
}
I am given that the method must be structured as "public double distance (Point otherPoint)" but I don't fully understand how this method should work with the point objects. I will use these point methods in my Rectangle class in order create a getLength() getWidth() getPerimeter() and getArea() methods. So everything builds off of getting the Point() class working correctly.