I am doing a mini-project using java to determine the cost of a speeding ticket:
Code:
// Import of scanner
import java.util.Scanner;
public class SpeedingTicket
{
public static void main(String[] args)
{
// Cost of each fee (Constants)
final int MIN_FEE = 50;
final int SCHOOL_FEE = 12;
final int NORMAL_FEE = 6;
final int SPEED_THRESHOLD = 30;
final int SUPER_SPEEDING = 150;
// Input data
Scanner scan = new Scanner(System.in);
System.out.print("Enter driver's name: ");
String driverName = scan.nextLine();
System.out.print("Enter driver's speed: ");
int driverSpeed = scan.nextInt();
System.out.print("Enter speed limit: ");
int speedLimit = scan.nextInt();
System.out.print("Was driver in school zone: ");
String schoolZone = scan.next();
System.out.println();
// Calculation of speeding ticket cost
int baseFee = MIN_FEE;
int schoolSpeeding = SCHOOL_FEE * (driverSpeed - speedLimit);
int normalSpeeding = NORMAL_FEE * (driverSpeed - speedLimit);
int superSpeeding = SUPER_SPEEDING;
if (driverSpeed > speedLimit)
{
baseFee = MIN_FEE;
}
String yes = new String("yes");
if (schoolZone.equalsIgnoreCase(yes))
{
schoolSpeeding = SCHOOL_FEE * (driverSpeed - speedLimit);
}
else
{
normalSpeeding = NORMAL_FEE * (driverSpeed - speedLimit);
}
if (driverSpeed > (speedLimit + SPEED_THRESHOLD))
{
superSpeeding = SUPER_SPEEDING;
}
// Display of speeding ticket information
System.out.printf("Speed traveled: %-3d \n", driverSpeed);
System.out.printf("Speed limit: %-6d \n", speedLimit);
System.out.printf("In school zone: %-3s \n", schoolZone);
System.out.print(driverName + " owes $");
System.out.println(baseFee + schoolSpeeding + normalSpeeding + superSpeeding);
System.out.println();
}
}
That's the code, however, once it's run and values are inputed, the output of the total ticket price does not make sense. Can anyone help?
Bookmarks