Question: Write a class, Coordinate that implements the Comparable interface.The class contains x, y and z attributes (type double), a constructor, and accessor and mutator methods

Write a class, "Coordinate" that implements the "Comparable" interface.The class contains "x", "y" and "z" attributes (type "double"), a constructor, and accessor and mutator methods for each of the attributes. Write a second class, CoordinateApp.java that contains a "main" method that performs the following. Add 3 objects of the "Coordinate" type to a PriorityQueue object . Use an iterative structure to display the elements from the queue in priority order (i.e., based on distance from the 0,0,0 coordinate; refer to compareTo method below)

The "compareTo" method will be based on the "Coordinate" object distance from the origin of 0, 0, 0. The formula for distance from the origin is below. distance = sqrt( (x - 0)2 + (y - 0)2 + (z - 02 ), where x,y & z are the components of the coordinate object

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!