CONSTRUCTORS
you have to represent a point in 2d space. Write a class with the name Point. The class needs two fields ( instance variable ) with name x and y of type int.
the class needs to have two constructors. the first constructors do not have any parameters (no-argument constructor). the second constructor has parameters x and y of type int and it needs to initialize the fields
writ the following methods
the method named getx without parameter---------------->return the value of x field.
the method named gety without parameter---------------->return the value of y field
the method named setx without parameter----------------->set the value of x field
the method named sety without parameter----------------->set the value of y field
the method named distance without parameter------------>dist. between the point and point (0,0)
the method named distance with parameter x and y------>dist. between the point and point (x,y)
the method named distance with parameter another of type point------------>dist. between the point and point (0,0)
public class Point {
private int x;
private int y;
public Point() {
this.x = 0;
this.y = 0;
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
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;
}
public double distance() {
double distancePoints = Math.sqrt(
(0 - getX()) * (0 - getX()) + (0 - getY() * (0 - getY()))
);
return distancePoints;
}
public double distance(int xx, int yy) {
double distancePoints = Math.sqrt(
((xx - getX()) * (xx - getX())) + ((yy - getY()) * (yy - getY()))
);
return distancePoints;
}
public double distance(Point point) {
double distancePoints = Math.sqrt(
((point.getX() - getX()) * (point.getX() - getX())) + ((point.getY() - getY()) * (point.getY() - getY()))
);
return distancePoints;
}
}