অনুশীলন
package bd.com.howtocode.java;
/**
* @author Bazlur Rahman Rokon
* @date 6/19/15.
*/
public class Point {
private int x;
private int y;
public Point() {
x = 0;
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(int x, int y) {
int xDiff = this.x - x;
int yDiff = this.y - y;
return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
}
public double distance(Point p2) {
return distance(p2.getX(), p2.getY());
}
@Override
public String toString() {
return "(" + x + ", " + ")";
}
}Last updated