java设计一个表示二维平面上点的类Point

来源:百度知道 编辑:UC知道 时间:2024/09/20 09:19:04
用Java设计一个表示二维平面上点的类Point,包含表示坐标位置的protected类型的成员变量x和y,以及获取和设置x和y值的public类型方法:getx()、gety()、setx()、sety()。Point类的构造方法要有多种形式。

class Point
{
protected int x;
protected int y;
Point() { }
Point( int x, int y ) { this.x = x; this.y = y; }
Point( Point p ) { this.x = p.getx(); this.y = p.gety(); }
public int getx() { return x; }
public int gety() { return y; }
public void setx( int x ) { this.x = x; }
public void sety( int y ) { this.y = y; }
}

class Point{
protected float x,y;
public Point(){

}
public Point(float x,float y){
this.x=x;
this.y=y;
}
public void setx(float x){
this.x=x;
}
public float getx(){
return x;
}
public void sety(float y){
this.y=y;
}
public float gety(){
return y;
}

}