Answer:
Java code is given below
Step-by-step explanation:
==================== Point.java ============================
public class Point implements Comparable<Point>{
public float x;
public float y;
public float z;
public Point(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public int compareTo(Point point) {
// TODO Auto-generated method stub
if(this.x != point.x){
return Double.compare(this.x, point.x);
}
if(this.y != point.y){
return Double.compare(this.y, point.y);
}
if(this.z != point.z){
return Double.compare(this.z, point.z);
}
return 0;
}
@Override
public String toString(){
return "(" + this.x + "," + this.y + "," + this.z + ")";
}
}
===================== Main Program file ===================================
import java.util.ArrayList;
import java.util.Collections;
public class Lab6Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Point> Points = new ArrayList<Point>();
Points.add(new Point(1,2,3));
Points.add(new Point(0,0,0));
Points.add(new Point(0,34,68));
Collections.sort(Points);
//Added the below lines to print the output
System.out.println(Points.get(0).toString());
System.out.println(Points.get(1).toString());
System.out.println(Points.get(2).toString());
}
}
=============== Output ==========================
(0.0,0.0,0.0)
(0.0,34.0,68.0)
(1.0,2.0,3.0)