I have a class box with 3 double values. The task is to sort one of the values and print the results. Below there is a code
public class Box implements Comparable<Box> {
private double x;
private double y;
private double z;
private double volume;
@Override
public int compareTo(Box o) {
return this.x > o.x ? 1 : this.x < o.x ? -1 : 0;
}
public static void sorting (Box[] o)
{
System.out.println();
for (int i = 0; i<o.length; i++)
{
System.out.println(o[i].x);
}
}
There is no errors in this code, but it is not sorting x parameter too.