JAVA编程题目 求高手解答?

2025-03-04 11:38:58
推荐回答(1个)
回答1:

你的要求基本上就是一个实体bean

public class Point {

private int x;

private int y;

public Point() {
// TODO Auto-generated constructor stub
}

public Point(int x, int y) {
// TODO Auto-generated constructor stub
this.x = x;
this.y = y;
}

public String toString() {
// TODO Auto-generated method stub
return "("+x+","+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;
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

Point p1 = new Point();
p1.setX(10);
p1.setY(10);

System.out.println("p1的坐标是:"+p1);

Point p2 = new Point(-10,20);

System.out.println("p2的坐标是:"+p2);
}

}