Subscribe to nelsonbc25's JavaBlog        RSS Feed
-----

Day 4: Traffic violations

Icon Leave Comment
/*
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;
		BufferedReader dataIn= new BufferedReader(new InputStreamReader(System.in));

		//User input

		System.out.println("Enter the actual speed limit: ");
			speedLimit = dataIn.readLine();
			milesLimit = Double.parseDouble(speedLimit);
		System.out.println("Enter the speed the offender was traveling: ");
			speedActual = dataIn.readLine();
			milesActual = Double.parseDouble(speedActual);
		System.out.println("Enter the total number of previous tickets: ");
			prevTickets = dataIn.readLine();
			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

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

April 2014

S M T W T F S
  12345
6789101112
13141516 17 1819
20212223242526
27282930   

Tags

    Recent Entries

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)