Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use the simplest code... Assignmnent 3: Decision Structures Due Date: 05/

ID: 3902122 • Letter: P

Question

Please use the simplest code...

Assignmnent 3: Decision Structures                                                                                         Due Date: 05/07/2018

(Decision Tree) The fines for Speeding in one of the counties in Florida is given in the following table.

MPH Over Speed Limit

Fine

Less than 10 MPH

$129.00

Less than 15 MPH

$204.00

Less than 20 MPH

$254.00

Less than 30 MPH

$279.00

Greater than or equal to 30 MPH

Court Mandatory

If you speed in school or construction zone your fine is doubled.

Write a Java program to calculate the speeding fine and display the speeding fine as output.

Create a Class with YourLastNameSpeedLimit

Use an if – else if – else loop to calculate the speeding fine.

Also consider the case where the driver is driving within the speed limit.

The program should ask the user to input the following three variables (Use Scanner).

Speed Limit,

Speed of the vehicle and

Whether construction or school zone (This could be a yes or no or a Y or N, You need to specify to the user what they should input).

Once the inputs are entered the program should calculate the speeding fines.

Example 1:

Speed Limit in MPH: 45

Vehicle speed in MPH: 57

Construction or School Zone: No

Total Fine Calculated = $204.00

Example 2:

Speed Limit in MPH: 45

Vehicle speed in MPH: 57

Construction or School Zone: Yes

Total Fine Calculated = $408.00

Assignmnent 3: Decision Structures                                                                                         Due Date: 05/07/2018

(Decision Tree) The fines for Speeding in one of the counties in Florida is given in the following table.

MPH Over Speed Limit

Fine

Less than 10 MPH

$129.00

Less than 15 MPH

$204.00

Less than 20 MPH

$254.00

Less than 30 MPH

$279.00

Greater than or equal to 30 MPH

Court Mandatory

If you speed in school or construction zone your fine is doubled.

Write a Java program to calculate the speeding fine and display the speeding fine as output.

Create a Class with YourLastNameSpeedLimit

Use an if – else if – else loop to calculate the speeding fine.

Also consider the case where the driver is driving within the speed limit.

The program should ask the user to input the following three variables (Use Scanner).

Speed Limit,

Speed of the vehicle and

Whether construction or school zone (This could be a yes or no or a Y or N, You need to specify to the user what they should input).

Once the inputs are entered the program should calculate the speeding fines.

Example 1:

Speed Limit in MPH: 45

Vehicle speed in MPH: 57

Construction or School Zone: No

Total Fine Calculated = $204.00

Example 2:

Speed Limit in MPH: 45

Vehicle speed in MPH: 57

Construction or School Zone: Yes

Total Fine Calculated = $408.00

MPH Over Speed Limit

Fine

Less than 10 MPH

$129.00

Less than 15 MPH

$204.00

Less than 20 MPH

$254.00

Less than 30 MPH

$279.00

Greater than or equal to 30 MPH

Court Mandatory

Explanation / Answer

import java.util.*;

import java.lang.*;

import java.io.*;

/* Please provide your last name as your class name */

class YourLastNameSpeedLimit

{

public static void main (String[] args) throws java.lang.Exception

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the speed limit in MPH");

int speedLimit=sc.nextInt();

System.out.println("Enter the vehicle speed in MPH");

int vehicleSpeed=sc.nextInt();

System.out.println("Construction or school zone");

char c = sc.next().charAt(0);

int fine=1;

if(c=='Y')

fine = 2;

else

fine = 1;

if(vehicleSpeed-speedLimit >= 30)

{System.out.println("Court mandatory");

}

else{

if(vehicleSpeed-speedLimit < 10 )

fine *= 129;

else if (vehicleSpeed-speedLimit < 15 )

fine *= 204;

else if (vehicleSpeed-speedLimit < 20)

fine *= 254;

else if (vehicleSpeed-speedLimit < 30)

fine *= 279;

System.out.println("Total fine calculated: "+ fine);

}

}

}