(1)可以生成具有特定坐标的点对象。
(2)提供可以设置三个坐标的方法
(3)提供可以计算该“点”距原点距离平方的方法
(4)提供可以计算该“点”距空间中任意一点
import java.util.Scanner;
public class Pointtest {
public Pointtest() {
}
public static void main(String[] args) {
Point p=new Point(0,0,0);
Point p2=new Point(1, 2, 1);
p.setX(22);
p.setY(2);
p.setZ(3);
System.out.println("坐标("+p.getX()+","+p.getY()+","+p.getZ()+")");
p.yuandian();
System.out.println("到任意一点距离"+p.dian(p2));
}
}
class Point {
int x;
int y;
int z;
public Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;}
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;
}
public int getZ(){
return z;
}
public void setZ(int z){
this.z = z;
}
public void yuandian(){
System.out.println(x*x+y*y+z*z);
}
public int dian(Point p2){
return ((x-p2.x)^2+(y-p2.y)^2+(z-p2.z)^2);
}
}
距离平方的方法