class Point {
public int x; //定义三点坐标
public int y;
public int z;
//编写构造器
public Point (int _x, int _y, int _z) {
x = _x;
y = _y;
z = _z;
}
//各自设置坐标的三个方法
public void setX(int _x) {
x = _x;
}
public void setY(int _y) {
y = _y;
}
public void setZ(int _z) {
z= _z;
}
//计算点到坐标原点距离的方法
public void cal() {
int len = x * x + y * y + z * z;
System.out.println("len = " + len);
}
//显示点坐标
public void display() {
System.out.println
("x = " + x + " y = " + y + " z = " + z);
}
}
public class Pointf {
public static void main (String[] args) {
Point a1 = new Point (1, 2, 3);
a1.display();
a1.cal();
a1.setX(50);
a1.display();
a1.cal();
a1.setY(50);
a1.setZ(50);
a1.display();
a1.cal();
}
}