3 回答
TA贡献1786条经验 获得超11个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | public class Point {
private double x;
private double y;
public Point(double x, double y) { super(); this.x = x; this.y = y; }
public double distance(Point point) { return Math.sqrt((point.x - this.x) * (point.x - this.x) + (point.y - this.y) * (point.y - this.y)); }
public Point move(double x, double y) { return new Point(this.x + x, this.y + y); }
@Override public String toString() { // TODO Auto-generated method stub return "(" + x + ", " + y + ")"; }
public static void main(String[] args) { Point p1 = new Point(5, 6); Point p2 = new Point(-2, -9);
System.out.println(p1.distance(p2)); System.out.println(p1.move(11, -2)); }
} |
TA贡献1824条经验 获得超8个赞
class Point{
int x;
int y;
public Point(int x,int y){
this.x = x;
this.y = y;
}
public void move(){
//要怎么移动。。。
}
public void test(){
//要测试什么。。。
}
}
添加回答
举报