Using Java code: Write a program that is given two integers representing a speed limit and driving speed in miles per hour (mph) and outputs the traffic ticket amount. Driving 10 mph under the speed limit (or slower) receives a $50 ticket. Driving 6 - 20 mph over the speed limit receives a $75 ticket. Driving 21 - 40 mph over the speed limit receives a $150 ticket. Driving faster than 40 mph over the speed limit receives a $300 ticket. Otherwise, no ticket is received.
Using Java code:
Write a program that is given two integers representing a speed limit and driving speed in miles per hour (mph) and outputs the traffic ticket amount.
Driving 10 mph under the speed limit (or slower) receives a $50 ticket. Driving 6 - 20 mph over the speed limit receives a $75 ticket. Driving 21 - 40 mph over the speed limit receives a $150 ticket. Driving faster than 40 mph over the speed limit receives a $300 ticket. Otherwise, no ticket is received.
The Algorithm of the code:-
1. Prompt the user to enter the speed limit.
2. Store the speed limit in a variable called "speedLimit".
3. Prompt the user to enter their driving speed.
4. Store the driving speed in a variable called "drivingSpeed".
5. Calculate the speed difference between the speed limit and the driving speed by subtracting the speed limit from the driving speed.
6. Store the speed difference in a variable called "speedDifference".
7. If the speed difference is less than or equal to -10, then print "You were driving too slowly. You have received a $50 ticket."
8. Else if the speed difference is greater than or equal to 6 and less than or equal to 20, then print "You were speeding. You have received a $75 ticket."
9. Else if the speed difference is greater than or equal to 21 and less than or equal to 40, then print "You were driving dangerously. You have received a $150 ticket."
10. Else if the speed difference is greater than 40, then print "You were driving extremely dangerously. You have received a $300 ticket."
11. Otherwise, print "You were within the speed limit. No ticket issued."
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images
I used the code above to create a program in Java and I receive the below errors:
java7 error: cannot find symbol
int speedLimit = input.nextInt();
symbol: variable input
java9 error: cannot find symbol
int drivingSpeed = input.nextInt();
symbol: variable input
2 errors