为Point类添加方法
王新港 2016-03-29 09:56:04 为Point类添加方法
public void translate(double x, double y);
其功能向右边移动当前点的位置x个单位,向上移动y个单位
Point 代码如下
package point;
public class Point {
private int x;
private int y;
public void setX(int x1){
x=x1;
}
public void setY(int y1){
y=y1;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public String toString(){
return"点"+x+","+y;
}
public static void main(String[] args) {
Point p0=new Point();
p0.setX(5);
p0.setY(6);
System.out.println("Point"+p0);
}
}