I would like to start by describing the goal my current project and the issue(s) I have with my current design/code.
The goal is to create a prompt that calculates speeding violation costs and output the fines and misc. information of the
driver.
Now what's troubling me is creating IF...THEN statements with the Boolean operator.
E.g. The prompt would print "Were you driving in a school zone? (True/False)"
I want to use the scanned input of True or False and make it do something else such as adding to the original fine.
Here's what I have so far, it's quite a lengthy chunk of code, but I appreciate any guidance that I receive.
I'm not here to ask for a solution then run with it, I'm here to seek a viable fix that I can learn from. Thank you.
P.S. I've commented out a large portion of my code because I'm still designing the logic behind my program.
import java.io.*;
import java.util.*;
public class Program1
{
public static void main (String args[] ) throws Exception
{
//Insert CONSTANTS here
//final int SPEED_LIMIT =
//final int BASE_FINE = 100
//final int UNDER_TWENTY =
//final int OVER_TWENTY =
//final int CONSTR_FINE = *2
//final int UNDER_FINE = 300
Scanner kbd = new Scanner (System.in);
//1st printed line displaying Penn State Police Department
System.out.println ("As a courtesy of the Pennsylvania State Police Department," +
"\n" + "you have received a written warning for violating Pennsylvania motor" +
"\n" + "vehicle law(s):" + "\n" );
//FirstName prompt; asking user to input legal first name
String FirstName;
System.out.print( "Enter your legal first name: ");
FirstName = kbd.nextLine();
System.out.println ( "\n" + "You have entered " + FirstName + " as your legal first name. " + "\n");
System.out.println ( "____________________________________________________________________" + "\n");
//LastName prompt; asking user to input legal last name
String LastName;
System.out.print( "Enter your legal last name: ");
LastName = kbd.nextLine();
System.out.println("\n" + "You have entered " + LastName + " as your legal last name. " + "\n");
System.out.println("_______________________________________________________________" + "\n");
//DriverAge prompt; asking user for his/her age in "x" years
System.out.print( "Enter your age (in years): ");
int DriverAge;
DriverAge = kbd.nextInt();
System.out.println("\n" + "You have entered " + DriverAge + " as your age in years. " + "\n");
System.out.println("_______________________________________________________________" + "\n");
//SpeedLimit prompt; asks for enforced speed limit
System.out.print( "Enter the enforced speed limit (in Miles Per Hour): ");
int SpeedLimit;
SpeedLimit = kbd.nextInt();
System.out.println("\n" + "You have entered " + SpeedLimit + " MPH" + " as the enforced speed limit. " + "\n");
System.out.println("_______________________________________________________________" + "\n");
//DriverSpeed prompt; asks for how fast the driver was going
//Used to compare to SpeedLimit
System.out.print( "Enter your actual speed (in Miles Per Hour): ");
int DriverSpeed;
DriverSpeed = kbd.nextInt();
System.out.println("\n" + "You have entered " + DriverSpeed + " MPH" + " as your actual speed of travel. " + "\n");
System.out.println("_______________________________________________________________" + "\n");
//Boolean operator; asks whether or not violation occured in construction zone
System.out.print( "Speeding in construction zone? (True/False) ");
boolean ConZone;
ConZone = kbd.nextBoolean();
//IF...ELSE for Boolean True or False
//Not functional, not printing the println; needs work.
if boolean ConZone == True {
System.out.println("\n" + "You were speeding in a construction zone. " + "\n");
System.out.println("_______________________________________________________________" + "\n");
}
else {
System.out.println("\n" + "You were not speeding in a construction zone. " + "\n");
System.out.println("_______________________________________________________________" + "\n");
}
//IF ... THEN
//5 MPH over speed limit
//Report and all prompts will still appear.
/*if ( milesOverLimit > 5)
{
System.out.println("Speeding over limit by at least 5 MPH." );
}
else
{
System.out.println("No speeding violation, have a nice day and drive safe." );
}
*/
//Else if driver is over limit by 20 MPH, $30/per 5 MPH over limit.
//Else if driver is more than 20 MPH over limit, $30/per 5 MPH over limit.
//If violation in construction zone, DOUBlE the fine.
//Underage penalty
//*2 original fine if speeder < 21 years of age and more than 20 MPH over limit
/*
if ( age < 21 && milesOverLimit > 20 )
{
System.out.println("Underage driving speeders receive a $300 fine." );
fine += 300;
}
else
{
System.out.println("You are of age to drive, no additional $300 fine added." );
}
if ( CONSTRU = True );
{
System.out.println("Traffic violation occured in construction zone." );
System.out.println("Original fine will be doubled for speeding in a construction zone." );
}
*/
//Decorative Border
System.out.println("**************Pennsylvania State Police Department*************" + "\n");
System.out.println("***************************************************************" + "\n");
/* Have to declare CONSTANTS and variables soon...
/* IF ... Else statements
/* IF ... Then statements
/* Do NOT mix the rates, either charged $30/5 MPH over OR $50/5 MPH over.
/* IF CONSTRUCTION ZONE, THEN numerically *2 the fine
/* IF driver < 21 AND && > 20 MPH over limit THEN + $300 as underage speeder fine
/* This is add-on fine, no doubling for the underage, only for construction does it double
*/
//Summary Report output below:
System.out.println(" Last Name: " + LastName + "\n");
System.out.println(" First Name: " + FirstName + "\n");
System.out.println(" Age of driver: " + DriverAge + "\n");
//System.out.println(" Enforced Speed Limit: " + "$" + SpeedLimit + "\n");
//System.out.println(" Miles Per Hour Over Speed Limit: " + "$" + SpeedOver + "\n");
//System.out.println(" Base fine for violation: " + "$" + BaseFine + "\n");
//System.out.println(" Construction Zone Penalty Fine: " + "$" + CONSTR_FINE + "\n");
//System.out.println(" Driving Underage Violation: " + "$" + UNDERAGE_FINE + "\n");
//System.out.println(" Accumulated Total of Violation: " + "$" + Total + "\n");
//Decorative Border
System.out.println("***************************************************************" + "\n");
System.out.println("**********Drive safe and we hope you have a nice day!**********" + "\n");
} // END MAIN
} // END class Program1
Error Prompt in cmd:

New Topic/Question
Reply



MultiQuote




|