Question: These are the directions, my current code, and the error.public class LabProgram { public static double calcToll ( int hour, boolean isMorning, boolean isWeekend )

These are the directions, my current code, and the error.public class LabProgram {
public static double calcToll(int hour, boolean isMorning, boolean isWeekend){
// Weekday toll rates
double before7amWeekday =6.15;
double from7amTo959amWeekday =8.95;
double from10amTo259pmWeekday =6.90;
double from3pmTo759pmWeekday =8.95;
double from8pmWeekday =6.40;
// Weekend toll rates
double before7amWeekend =6.05;
double from7amTo759pmWeekend =7.15;
double from8pmWeekend =6.10;
// Check if it is a weekend
if (isWeekend){
if (hour 7){
return before7amWeekend;
} else if (hour 20){
return from7amTo759pmWeekend;
} else {
return from8pmWeekend;
}
} else {// It's a weekday
if (hour 7){
return before7amWeekday;
} else if (hour 10){
return from7amTo959amWeekday;
} else if (hour 15){
return from10amTo259pmWeekday;
} else if (hour 20){
return from3pmTo759pmWeekday;
} else {
return from8pmWeekday;
}
}
}
public static void main(String[] args){
// Test cases
System.out.println(calcToll(8, true, false)); // Should return 8.95
System.out.println(calcToll(1, false, false)); // Should return 6.90
System.out.println(calcToll(3, false, true)); // Should return 7.15
System.out.println(calcToll(5, true, true)); // Should return 6.05
System.out.println(calcToll(7, false, false)); // Should return 8.95
System.out.println(calcToll(11, false, false));// Should return 6.90
System.out.println(calcToll(1, false, true)); // Should return 6.05
System.out.println(calcToll(10, false, true)); // Should return 7.15
}
}
 These are the directions, my current code, and the error.public class

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!