Closed rvaughan74 closed 2 years ago
What does the code in question look like?
class ProductionRemoteControlCar implements RemoteControlCar, Comparable<ProductionRemoteControlCar> {
private int distance;
private int victories;
private final int driveDistance = 10;
public ProductionRemoteControlCar() {
this.distance = 0;
this.victories = 0;
}
public void drive() {
this.distance += driveDistance;
}
public int getDistanceTravelled() {
return this.distance;
}
public int getNumberOfVictories() {
return this.victories;
}
public void setNumberOfVictories(int numberofFictories) {
this.victories = numberofFictories;
}
public int compareTo(ProductionRemoteControlCar y) {
Integer xVictories = new Integer(this.victories);
Integer yVictories = new Integer(y.getNumberOfVictories());
return xVictories.compareTo(yVictories);
}
}
OK, so that code does in fact use a deprecated API: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Integer.html#%3Cinit%3E(int)
Creating new boxed primitive types using their constructors is a bad practice for the reasons described in the Javadoc. You should use Integer.valueOf
instead if you need to create the boxed version.
That being said, in that exercise you can just return this.victories - y.victories
.
NOTE: We are currently re-writing the Java test runner so the exact output may change soon. See #29
Oops... surprised my local JVM didn't throw an exception.
I get the following message from Exercism but not my local machine.
My Local machine version