Java program that can be used to calculate and notify


Java program that can be used to calculate and notify violators of the fines and/consequences for road traffic breaches as shown in the schedule below.

The violation notice may comprise of any of the following:

- One or more of non-moving violations alone.
- Combination of non-moving violations, and one kind of moving violation for excess speeding, or speeding in construction zone, but not both.
- Combination of non-moving violations, and one kind of moving violation for speeding in school zone, or speeding in toll facility, but not both.

Non-Moving Violation
- No driver's license $25.00
- Expired tag $20.00
- No registration $20.00
- No insurance $10.00

Moving Violation
-Speeding violation or speeding in construction zone Miles over the Speed Limit o 1 - 5 MPH Warning o 6 - 9 MPH $130.00 o 10 - 14 MPH $205.00 o 15 - 19 MPH $405.00 o 20 - 29 MPH $455.00 o 30 MPH or over $605.00 and court appearance
-Speeding in school zone or speeding within a toll facility o 1 - 5 MPH $155.00 o 6 - 9 MPH $255.00 o 10 - 14 MPH $305.00 o 15 - 19 MPH $405.00 o 20 - 29 MPH $455.00
2

-One kind of moving violation only, for excess speeding, or speeding in construction zone, but not both.
-One kind of moving violation for speeding in school zone, or speeding in toll facility, but not both.

In formulating your solution: (a) class called TrafficViolations that determines types of traffic violations. (b) test class called TestTrafficViolations that implements the class TrafficViolations (c) Demonstrate knowledge of the if statement and the switch statement by using the if/else statement to determine the miles, and the switch statement for the other criteria. (d) You determine a suitable format for the output

This is what I have so far...

import java.util.*;
import java.lang.*;
import java.io.*;
class TrafficViolations
{
public static void trafficviolation()
{
int speed;
int lic;
int registration;
int insurance;
double fine =0;
double sfine=0;
int location;

Scanner scan = new Scanner(System.in);
System.out.println(" Do you have license (1/0) 1 for yes or 0 No ( for No driver license $25.00)");
lic=scan.nextInt();
System.out.println(" Tag expired (1/0) 1 for yes or 0 No ( for Expired tag $20.00)");
int tag=scan.nextInt();
System.out.println(" Do you have No Registration (1/0) 1 for yes or 0 No ( No registration $20.00)");
registration=scan.nextInt();
System.out.println(" Do you have Insurance(1/0) 1 for yes or 0 No (No insurance $10.00)");
insurance=scan.nextInt();
//Moving Violation
//Speeding violation or speeding in construction zone
System.out.println(" Enter Speed ");
speed =scan.nextInt();
System.out.println(" Enter location (Enter 1/0) if school area 1 otherwise zero ");
location= scan.nextInt();
if(lic==0)
{
fine=fine+25;
}
if(insurance==0)
{
fine=fine+10;
}
if(registration==0)
{
fine=fine+20;
}
//Miles 0ver the Speed Limit
if (speed>1 &&speed <=5 )
{
System.out.println("Warning: Miles Over the Speed Limit please drive below the speed limit");
}
if (speed>6 &&speed <=9 )
{
sfine=sfine+130.00;
}
if(speed>10 && speed <=14 )
{
sfine=sfine+205.00;
}
if(speed>=15 && speed<=19 )
{
sfine=sfine+405.00;
}
if (speed>20 && speed<=29 )
{
sfine=sfine+455.00;
}
if (speed>30 )
{
sfine=sfine+605.00;
System.out.println(" Court appearance needed if speed is more than 30");
}
//Speeding in school zone or speeding within a toll facility
if (speed>1 &&speed <=5 && location ==1)
{
sfine=sfine+155.00;
System.out.println("Warning: Miles Over the Speed Limit please please drive below the speed limit");
}
if (speed>6 && speed <=9 && location ==1 )
{
sfine=sfine+255.00;
}
if (speed>10 && speed <=14 && location ==1 )
{
sfine=sfine+305.00;
}
if (speed>15 && speed <=19 && location ==1)
{
sfine=sfine+405.00;
}
if (speed>20 && speed <=29 && location ==1)
{
sfine=sfine+455.00;
}
System.out.println("Fine for Non Moving ViolationFine"+fine);
System.out.println("Fine for Moving ViolationFine"+sfine);
System.out.println("Fine for Non Moving+Moving ViolationFine"+(fine+sfine));
}
}

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Java program that can be used to calculate and notify
Reference No:- TGS02361099

Now Priced at $10 (50% Discount)

Recommended (97%)

Rated (4.9/5)