空间点

 1 public class Point {
 2     private double x;
 3     private double y;
 4     private double z;
 5 
 6     public double getX() {
 7         return x;
 8     }
 9 
10     public void setX(double x) {
11         this.x = x;
12     }
13 
14     public double getY() {
15         return y;
16     }
17 
18     public void setY(double y) {
19         this.y = y;
20     }
21 
22     public double getZ() {
23         return z;
24     }
25 
26     public void setZ(double z) {
27         this.z = z;
28     }
29 
30     public Point(double x, double y, double z) {
31         this.x = x;
32         this.y = y;
33         this.z = z;
34     }
35 
36     public void getJuLi() {
37         System.out.println("点(" + x + "," + y + "," + z + ")距离原点的平方=" + (x * x + y * y + z * z));
38     }
39 
40     public static void main(String[] args) {
41         Point p = new Point(5, 3, 8);
42         p.setY(-2.5);
43         p.getJuLi();
44 
45         Point p1 = new Point(-1, 3, 5);
46         p1.getJuLi();
47 
48     }
49 
50 }

定义一个“点”(Point)类用来表示三维空间中的点(有三个坐标)。要求如下:

(1)可以生成具有特定坐标的点对象。

(2)提供可以设置三个坐标的方法。

(3)提供可以计算该“点”距原点距离平方的方法。

(4)编写主类程序验证。

原文地址:https://www.cnblogs.com/ouyangtangfeng99/p/5526469.html