Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

2. How will you handle the situation?

Answered: 1 week ago