CS1083/Source Code/Midterm/CarComparable.java
2022-10-07 00:44:12 -03:00

41 lines
912 B
Java

public class Car implements Comparable<Car>{
private String brand;
private int year;
public Car(String brandIn, int yearIn){
brand = brandIn;
year = yearIn;
}
public int compareTo(Car otherCar) {
if (brand.compareTo(obj2) > 0) {
return 1;
}
else if (obj1.compareTo(obj2) < 0) {
return -1;
}
else {
int obj1Int = Integer.parseInt(String.valueOf(code.charAt(1) + code.charAt(2) + code.charAt(3)));
int obj2Int = Integer.parseInt(String.valueOf(other.getCode().charAt(1) + other.getCode().charAt(2) + other.getCode().charAt(3)));
if (obj1Int < obj2Int) {
return 1;
}
else if (obj1Int > obj2Int) {
return -1;
}
return 0;
}
}
}