抱歉,如果我的问题看起来很愚蠢。我在 .compareTo() 上收到错误无法在原始类型 double 上调用 compareTo(double)!我怎样才能解决这个问题 ?谢谢!
车辆等级:
public class Vehicle implements IOutput {
private double cost;}
public double getCost(){
return cost;
}
数组类:
public static void sortByVehicleMakeModel(Vehicle[] vehicles) {
boolean swapped = true;
for(int y = 0; y < vehicles.length && swapped; y++) {
swapped=false;
for(int x = 0; x < vehicles.length - (y+1); x++) {
if(vehicles[x].getCost().compareTo(vehicles[x + 1].getCost()) > 0){
swap(vehicles, x, x + 1);
swapped=true;
}
}
}
}
我的其他代码工作正常:
public static void sortByOwnerName(Vehicle[] vehicles) {
boolean swapped = true;
for(int y = 0; y < vehicles.length && swapped; y++) {
swapped=false;
for(int x = 0; x < vehicles.length - (y + 1); x++) {
if(vehicles[x].getOwner().getName().compareTo(vehicles[x + 1].getOwner().getName())> 0) {
swap(vehicles, x, x + 1);
swapped=true;
}
}
}
}