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
Step: 1
Get Instant Access to Expert-Tailored Solutions
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