私の質問が非常に愚かに見える場合は申し訳ありません。.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;
}
}
}
}