I am doing a homework (composite classes on calculating the distance between two points. I have classes (Line, Point and Main). I have to use the methods my teacher designed on UML. However, i found that i am able to calculate the distance without fulfilling some of the methods . I'm just wondering if anyone knows what they are for.
I believe they are used to calculate and return the distance of Point P. However, Point P has only 1 point so how can it be calculated? Or maybe Point P takes the value of my second constructor and copy constructor and form a calculation? Thank you all for your help.
These are my code below:
Class Point
class Point
{
private int x;
private int y;
//default constructor
public Point()
{
//do nothing
}
// second constructor
public Point(int x, int y)
{
this.x=x;
this.y=y;
}
// Copy constructor
public Point (Point p)
{
this (p.x,p.y);
}
private double distance(Point p)
{
// how can i calculate distance with just a single point?
}
public double getDistance(Point p)
{
// how can i return distance with just a single point?
}
// getter
public int getX()
{
return x;
}
public int getY()
{
return y;
}
/setter
public void set(int x, int y)
{
this.x = x;
this.y = y;
}
My main method will generate random integer and instantiate an object with the following outcome:
Point 1 (43, -90)
Point 2 (-70, -34)
Distance (126.1150)