X213: ticketCost

The speed limit on a highway is 100 km/h. Drivers exceeding the speed limit are issued a ticket. The amount of the ticket charge depends on two things: whether it is their first offense, and the amount over the speed limit at which they were driving:

Speed (km/h) First Offense? Charge ($)
<= 100 Not applicable 0
101-120 Yes 105
>= 121 Yes 160
>= 101 No 200

Write a method called ticketCost() that takes the speed (as an int) and whether or not this is a first offense (a boolean) as its parameters. This method should return the cost of the corresponding ticket. You are required to use nested if-statements to solve this question.

Examples:

ticketCost(80, false) -> 0
ticketCost(110, true) -> 105

Your Answer:

Feedback

Your feedback will appear here when you check your answer.