Lab Exercise 06.2 Coordinate Geometry The purpose of this exercise is to demonst
ID: 3904358 • Letter: L
Question
Lab Exercise 06.2 Coordinate Geometry The purpose of this exercise is to demonstrate class reusability by creating a class that is useful in a variety of contexts. You will design and code a class named Point which can represent a geometric point with x-, y- and z-coordinates. The class will contain . A private, class-level variable, a String. which will be the point's ID Three private, class-level integer variables x, y and z that represent the coordinates of the point. A no-argument (default) constructor that initializes x, y and z with 0 values. A constructor that accepts three arguments and initializes x, y and z with those values. . A getX() method, a getY) method and a getZO method. .A getlD) method . A method named distance that returns the distance from this point to another point. public int distance point p) I have written a main to test your class. This main method will test the point class and all of its methods by generating an ArrayList of 8 points (at x, y and z values -15 to +15). The test program will supply pairs of points by using two String values, (ID names for two points). The program will then display the distance between the two specified points. This will be done for a number of point-pairs.Explanation / Answer
Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
public class Point {
private String ID;
private int x, y, z;
public Point()
{
x = 0;
y = 0;
z = 0;
ID = "";
}
public Point(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
this.ID = "";
}
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
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 int distance(Point p)
{
int dx = x - p.x;
int dy = y - p.y;
int dz = z - p.z;
return (int)Math.sqrt(dx * dx + dy * dy + dz * dz);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.