1、定义一个点类Point,包含2个成员变量x、y分别表示x和y坐标,2个构造器Point()和Point(int x0,y0),以及一个movePoint(int dx,int dy)方法实现点的位置移动,创建两个Point对象p1、p2,分别调用movePoint方法后,打印p1和p2的坐标。[必做题]
package Homework6_5;
public class Point {
public int x;
public int y;
public Point() {
}
public Point(int x0, int y0) {
this.x=x0;
this.y=y0;
}
public void movePoint(int dx,int dy) {
System.out.println("移动前的坐标为:"+this.x+this.y);
System.out.println("移动量:"+dx+dy);
this.x+=dx;
this.y+=dy;
System.out.println("移动后的坐标为:"+this.x+this.y);
}
public static void main(String[] args) {
Point p1=new Point(1,2);
Point p2=new Point(3,4);
p1.movePoint(p2.x,p2.y);
}
}