Create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class
Create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class.
The Point3D class will have the following state and functionality:
Three data fields, x, y and z, of type double, represent the point’s coordinates
Additional data field, colour, of type String, represents the point's color
A no-arg constructor creates a point at position (0, 0, 0) and "Red" colour.
Another constructor creates a point with specified coordinates and colour.
A getter method is provided for each of the fields.
An accessor method named distance returns the distance between the current point and another point passed as an argument.
The distance method is overloaded to accept the coordinates of the other point.
Write a TestPoint3D class that will have a main method, and perhaps other methods as required by good design, to test your Point3D class. It will not have user input because this class will stand as a record of the tests you have applied and you will be able to run it whenever you alter your Point3D class. For the TestPoint3D class you will need to do the following:
Test the basic state and functionality of the Point3D class. Each of the constructors and each of the methods should be tested using some different data values. The test code should display values so that they can be checked.
Write some code to create an array of at least 10 Point3D objects.
Write a method max, which will accept the array of points as an argument, and will calculate and display the maximum distance between the points in the array, and the pair of points for which the maximum occurs.
Write a method min, which will accept the array of points as an argument, and will calculate and display the minimum distance between the points in the array, and the pair of points for which the minimum occurs.
Step by Step Solution
3.46 Rating (162 Votes )
There are 3 Steps involved in it
Step: 1
Point3Djava public class Point3D instance variables private double x private double y private double z private String colour constructors public Point3D x 0 y 0 z 0 colour Red public Point3Ddouble x d...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started