Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
}
}
image text in transcribed

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions