如何在java中通过point类读取多个点?
public class point3d {
float x;
float y;
float z;
public point3d(float x, float y, float z){
this.x = x;
this.y = y;
this.z = z;
}
public point3d(){
x = 0;
y = 0;
z = 0;
}
public float getX(){
return x;
}
void setX(float x) {
this.x =x;
}
public float getY(){
return y;
}
void setY(float y) {
this.y =y;
}
public float getZ(){
return z;
}
void setZ(float z) {
this.z = z;
}
public String toString()
{
return "(" + x + ", " + y + "," + z + ")";
}
}
这是我编写的一个point3d类代码,我想通过这个point3d类读取多个点,这些点在主类中给出,我如何实现这一点。请帮帮我好吗
# 1 楼答案
首先,根据Naming Conventions,类应该以大写字母开头
其次,应该在主类中为
Point3d
创建一个容器,例如List
接下来,您可以迭代它并执行您的逻辑
接下来的问题是,你想用这些
points
实现什么# 2 楼答案
我想我现在明白你的问题了。你想制作一个三维矩形,这意味着你需要4个点(除非你想让它也有深度,在这种情况下你需要8个)
所以你只需要一个由4个
point3d
类组成的数组:然后你只需要分配给这个数组:
当您以后想要访问它们时:
我建议你读一读:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html