Question: What is wrong with my code that my test class output does not match the expected values? public class ShuttleBatteryMonitor { private int shortRate; private

What is wrong with my code that my test class output does not match the expected values?
public class ShuttleBatteryMonitor {
private int shortRate;
private int shortLimit;
private int longRate;
private int chargeCapacity;
private int numPassengers;
private int currLocation;
private int chargeLevel;
private int numTrips;
private int totalChargeUsage;
public ShuttleBatteryMonitor(int shortRate, int shortLimit, int longRate, int chargeCapacity){
this.shortRate = shortRate;
this.shortLimit = shortLimit;
this.longRate = longRate;
this.chargeCapacity = chargeCapacity;
numPassengers =0;
currLocation =0;
chargeLevel = chargeCapacity;
numTrips =0;
totalChargeUsage =0;
}
public void travelTo(int destination){
travelToHelper(destination, shortLimit, shortRate);
}
public void travelTo(int destination, int shortLimitOverride, int longRateOverride){
travelToHelper(destination, shortLimit, shortRate);
}
private void travelToHelper(int destination, int shortLimitOverride, int longRateOverride){
int distance = Math.abs(currLocation - destination);
currLocation = destination;
int shortRateUsage = numPassengers * shortRate * Math.min(shortLimitOverride, distance);
int longRateUsage = numPassengers * longRate * Math.max(distance - shortLimitOverride, 0);
int batteryUsageForCurrentTrip = shortRateUsage + longRateUsage;
chargeLevel -= batteryUsageForCurrentTrip;
numTrips++;
totalChargeUsage += batteryUsageForCurrentTrip;
}
public void recharge(){
currLocation =0;
chargeLevel = chargeCapacity;
}
public void loadPassengers(int netAddedPassengers){
numPassengers += netAddedPassengers;
if (numPassengers <0){
numPassengers =0;
}
}
public int getLocation(){
return currLocation;
}
public int getPassengerCount(){
return numPassengers;
}
public double getChargeRemaining(){
double remainingCharge =((double) chargeLevel / chargeCapacity)*100.0;
remainingCharge =(int)(10* remainingCharge)/10.0;
return remainingCharge; // TODO: Replace this placeholder
}
public double getAverageUsagePerTrip(){
// TODO: Your implementation goes here
if (numTrips ==0){
return 0; // TODO: Replace this placeholder
}
return (double) totalChargeUsage / numTrips;
}
public int getEstimatedTripsRemaining(){
if (getAverageUsagePerTrip()==0){
return 0; // TODO: Replace this placeholder
}
return (int)(chargeLevel / getAverageUsagePerTrip());
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!