Question
Decision or Selection Structures and Loops (Decision Tree: If else if else loop) The fines for Speeding in one of the counties in Florida is
Decision or Selection Structures and Loops
(Decision Tree: If else if else loop) The fines for Speeding in one of the counties in Florida is given in the following table. Use if else if else decision structure.
MPH Over Speed Limit | Fine |
Less than 5 MPH | $39.50 |
Less than 15 MPH | $89.00 |
Less than 25 MPH | $109.50 |
Less than 35 MPH | $149.99 |
Greater than or equal to 35 MPH | Court Mandatory Fine decided in court |
If the driver is driving greater than or equal to 35 mph over the speed limit, fine is calculated as $0.00 and Court Mandatory message should be displayed as shown in the table above.
Write a JAVA method to calculate the speeding fine speedFineCalcFirstname called from main.
The variables in the program should be named as shown below and should be input by the user:
speedLimitFirstname //(Speed Limit of the zone as an int)
speedFirstname // ( Speed of the vehicle as an int)
driv_teenFirstname // ( A string data type) The question here is whether the Driver is a Teenager. The acceptable values are the following: teen, t, no or n. Prompt the user to enter only these four values as entry. If any other value is entered by the user tell the user that the input is invalid and use a while loop to make sure that the correct input is used.
If the driver is a teenager ( driv_teen value is teen or t ) whatever fine calculated from the above table is tripled ( 3 times the fine from the table above ).
The program also should display the following message for each of the above cases as shown in the table below: (10)
Less than 5 MPH | You can do better as a Driver ! |
Less than 15 MPH | Please reduce your speed ! |
Less than 25 MPH | Be careful, you are driving reckless! |
Less than 35 MPH | You are over speeding. ! |
Greater than or equal to 35 MPH | Fine has to be calculated by court. !! |
Display also should specify whether you are a Teenager or not.
Your function should calculate the fine and also should do the display.
Function should not calculate any fine if the driver is driving within the speed limit with a message. You are a good Driver.
Fines should be calculated using an if - else if - else decision structure and make it more efficient by not repeating code as much as possible.
Display Message should be displayed using a Switch Case decision structure.
(Following are examples which you can use for testing. Please do not code for these values. Program should be always general. )
#Case 1: When Driver is not a teenager
Speed Limit: 45
Vehicle speed: 57
Teen Driver: no
Total Fine Calculated = $89.00
Display: Please reduce your speed !
#Case 2: When Driver is Teenager
Speed Limit: 45
Vehicle speed: 57
Teen Driver: teen
Total Fine Calculated = $267.00
Display: Please reduce your speed !
#Case 3: When Teenager is driving and a different vehicle speed
Speed Limit: 45
Vehicle speed: 49
Teen Driver: t
Total Fine Calculated = $118.50
Display: You can do better as a Driver !
#Case 4: When Teenager is driving and a different vehicle speed
Speed Limit: 45
Vehicle speed: 85
Teen Driver: t
Total Fine Calculated = $0.00
Court Mandatory Fine decided in court
Display: Fine has to be calculated by court. !!
In JAVA!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started