Write a function speedingFine that returns a double representing the cost of a speeding ticket based on the speed and whether or not the speeding occurred in a school zone. This information is represented by function inputs (parameters) int speed and boolean schoolZone. The function "signature" (its first line, including type, name, and inputs) has been provided for you.
The cost of a ticket is $22.50 for every 5 mph over the speed limit of 30 mph. Note that someone going 10 mph over the speed limit gets the same fine as someone going 12 or 14 mph since those speeds did not reach a new multiple of 5. That value is then tripled if the speeding was in a school zone.
You don't have to worry about speeds under the speed limit. Speeds 1-4 mph over getting no fine (the function should return 0).
Here's the problem: I'm stuck on a particular part, and that's the 5 mph part. I do have some scripts, but they only work for some cases. So the starting I have is this:
double speedingFine(int speed, boolean schoolZone) {
double times = 0;
if (speed < 35) {
return 0;
}
if (speed == 35 && schoolZone == false) {
return 22.5;
} else if (speed == 35 && schoolZone == true) {
return 67.5;
}
if (speed > 35) {
// I'm stuck here. I've thought of a while loop or some sort of loop here. I'm just trying to figure out how to section it
}
}
Can you help me on the loop part?