I want to sort Vehicles array based on seats
. I tried looking for solutions here, but whenever I pass to compareTo
method a Vehicle
object, I get error in all my other files with classes for e.g The type Bike must implement the inherited abstract method Comparable.compareTo(Object)
. Can someone help me with this code?
public abstract class Vehicle implements Comparable {
protected int seats;
protected int wheels;
protected int price;
protected int weight;
public int compareTo(Vehicle o) {
return -1;
}
public static void main(String [] args) {
Car Lamborghini = new Car(5,4,30000, 1500);
Bike BMX = new Bike(1,2,300, 15);
Vehicle Vehicles[] = new Vehicle[2];
Vehicles[0] = Lamborgini;
Vehicles[1] = Bmx;
Arrays.sort(Vehicles);
for(int i=0;i<Vehicles.length;i++) {
System.out.println(Vehicles[i]);
}
}