Transit Calculator help

Hello, could you please help me finding the mistake, instead of

You should choose the 30 Day Unlimited at 1.6710526315789473 per ride.
You should choose the Single Ride at 2.75 per ride.
You should choose the 7 Day Unlimited at 1.03125 per ride.
I am getting
You should get the 7-day Unlimited Rides at 0.07486388384754991 per ride.
You should get the 7-day Unlimited Rides at 5.5 per ride.
You should get the 7-day Unlimited Rides at 0.29464285714285715 per ride.

What did I do wrong?

public class TransitCalculator {
int daysPub;
int numRid;
String rideOptions = {“Pay-per-ride”, “7-day Unlimited Rides”, “30-day Unlimited Rides” };
double passCost = {2.75, 33, 127};

public TransitCalculator(int daysPublic, int numberRides){
daysPub = daysPublic;
numRid = numberRides;
}
public double unlimited7Price(){
int numPass = daysPub/7;
if (numPass%7!=0) numPass++;
if (daysPub < 7 && daysPub >0) numPass =1;
double passCost7 = numPass*passCost[1];
return passCost7/numRid;
}

public double getRidePrices(){
double compare = {passCost[0]*numRid, unlimited7Price(), passCost[2]};
return compare;
}

public String getBestFare(){
int num = 0;
for (int i = 0;i<3;i++){
if (getRidePrices()[i] < getRidePrices()[num] ){
num = i;
}
}
return “You should get the " + rideOptions[num] + " at " + getRidePrices()[num]/daysPub + " per ride.”;

}

public static void main(String args){
TransitCalculator check1 = new TransitCalculator(29,76);
TransitCalculator check2 = new TransitCalculator(1,6);
TransitCalculator check3 = new TransitCalculator(7,32);
System.out.println(check1.getBestFare());
System.out.println(check2.getBestFare());
System.out.println(check3.getBestFare());
System.out.println(check1.unlimited7Price());
System.out.println(check2.unlimited7Price());
System.out.println(check3.unlimited7Price());

}
}

1 Like

Hi,

Thanks for sharing your code! We need a little bit more specificity.

Comment out your print statements and check that every method you wrote is working as intended (by writing print statements that you’ll comment out later). The good news is that your methods are not creating an error, so it’s just a matter of figuring out how they’re not adding up.

You’ll find that it’s very common to have to do this technique while learning to program. It’s quite useful to refine it.

1 Like