Subscribe to nelsonbc25's JavaBlog

## Day 4: Traffic violations

```/*
Chapter 3:	Assignment 6
Date:		3/15/10
Filename:	Traffic
Purpose:	An application that calculates the total charges for traffic violations
*/

import java.io.*;
import java.awt.*;
import java.util.*;

public class traffic
{
public static void main(String[]args) throws IOException
{
//declare class variables
String speedLimit, speedActual, totalCharge, speedDiff, prevTickets;
double milesLimit=0.0, milesActual=0.0, dollarsTotal = 0.0, milesDiff=0.0;
int numOfTickets=0;

//User input

System.out.println("Enter the actual speed limit: ");
milesLimit = Double.parseDouble(speedLimit);
System.out.println("Enter the speed the offender was traveling: ");
milesActual = Double.parseDouble(speedActual);
System.out.println("Enter the total number of previous tickets: ");
numOfTickets = Integer.parseInt(prevTickets);

//Calculate speed over the limit
milesDiff = milesActual - milesLimit;
//Calculate total fee
dollarsTotal = getCharge(milesDiff,numOfTickets, milesDiff);
}//end main

public static double getCharge(double speedDiff, int numOfTickets, double milesDiff)
{
double dollarsTotal = 0.0;
if(numOfTickets==0) dollarsTotal=((speedDiff*20)+74.80);
else if(numOfTickets>=1)
if(numOfTickets<=3) dollarsTotal = ((speedDiff*20 + 25*numOfTickets)+74.80);
else if(numOfTickets>3) dollarsTotal = (((speedDiff*20)+75+74.80));
if(speedDiff<=0) System.out.println("Offender should not have a ticket and does not owe anything");
else if(speedDiff>0) System.out.println("With "+numOfTickets+" previous tickets, and exceeding the speed limit by "+milesDiff+" MPH, their total cost is: "+dollarsTotal);
return dollarsTotal;
}//end getCharge
}//end traffic

```

### 0 Comments On This Entry

There are no Trackbacks for this entry

S M T W T F S
1234567
891011121314
15161718192021
222324 25 262728
2930