Question: Write a class called Compare3DPoint that defines a natural ordering by implementing the Comparable interface (Use CalenderDate class as your reference). Compare the Points by

Write a class called Compare3DPoint that defines a natural ordering by implementing the Comparable interface (Use CalenderDate class as your reference). Compare the Points by z-major order; that is, point with smaller z-coordinate values should come before those with higher z-coordinate values. If z value is the same then compare y-coordinate values. If z and y values are the same then compare x-coordinate values. Also, write a toString method to return x, y, and z value in the parenthesis.

Use the following code as a client program to test your Compare3DPoint class.

import java.awt.*; import java.util.*; public class Compare3DPointClient { public static void main(String[] args) { ArrayList points = new ArrayList(); points.add(new Compare3DPoint (3, 41, 100)); points.add(new Compare3DPoint (25, 36, 100)); points.add(new Compare3DPoint (19, 36, 100)); 12 points.add(new Compare3DPoint (25, 24, 50)); 13 points.add(new Compare3DPoint (44, 12, 40)); 14 15 System.out.println("Before = " + points); 16 Collections.sort(points); 17 System.out.println("After = " + points); 18 } 19 }

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!