java例程练习(Point类及简单测试)

public class Test {
	public static void main(String[] args) {
		Point p = new Point(1.0, 2.0, 3.0);
		System.out.println(p.getDistance(new Point(0.0, 0.0, 0.0)));
		
		p.setX(5.0);
		System.out.println(p.getDistance(new Point(0.0, 0.0, 0.0)));
		
	}
}


class Point {
	private double x;
	private double y;
	private double z;
	
	Point(double x, double y, double z) {
		this.setX(x);
		this.setY(y);
		this.setZ(z);
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getX() {
		return x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public double getY() {
		return y;
	}

	public void setZ(double z) {
		this.z = z;
	}

	public double getZ() {
		return z;
	}
	
	public double getDistance(Point p) {
		return (x - p.x)*(x - p.x) + (y - p.y)*(y-p.y) + (z - p.z)*(z - p.z);  
	}
	
	
}

你可能感兴趣的:(java,String,测试,Class)