Question
Please help me edit this Java code to match our new instructions that are shown at the bottom. I dont understand why I cant use
Please help me edit this Java code to match our new instructions that are shown at the bottom. I dont understand why I cant use the && operand in the if statements to calculate the fines and i really need help with calculating the Reckless Driving fines. Thank you
// Edit and add to student's IC2 code for IC3 import java.util.Scanner; public class esudde00IC3 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int speedLimit, actualSpeed, previousTickets; // Prompting user for input System.out.print("What is the speed limit? "); speedLimit = keyboard.nextInt(); System.out.print("What was the driver's actual speed? "); actualSpeed = keyboard.nextInt(); System.out.print("How many previous tickets do they have? "); previousTickets = keyboard.nextInt(); // Calculating costs with methods double fineCost = calcFine(actualSpeed, speedLimit); double penaltyCost = calcPenalty(previousTickets, fineCost); double recklessCost = calcReckless(actualSpeed, speedLimit); // Outputting to formatted print statements System.out.printf("Fine\t\t\t$%,.2f ", fineCost); System.out.printf("Penalty\t\t\t$%,.2f ", penaltyCost); System.out.printf("Reckless Driving\t$%,.2f ", recklessCost); System.out.printf("Total due\t\t$%,.2f", fineCost + penaltyCost + recklessCost); // Cleanup keyboard.close(); }// end of main /** * The calcFine method calculates the fine based on the difference between y and x * @param y // the speed the driver was going * @param x // the speed limit * @return the cost of the fine */ public static double calcFine(int y, int x) { double fine = 0; int difference = y - x; //if(difference <= 0) { do not need this b/c it does nothing // Do nothing //} /*else if (difference < 15) { fine = 250; }*/ //need to change from else if to if, difference and fine amount if (difference < 10) { fine = 200; } /*else if(difference < 30) { change difference operand and value and fine amount fine = 350;*/ else if(difference >= 10) { fine = 300; } /*else { needs to be another else if and values need changed fine = 450;*/ else if(difference >= 20) { fine = 400; } else if (difference >= 30) {//added code for IC3 fine = 500; } return fine; } /** * The calcPenalty method calculates the penalty based on the amount of tickets and the fine * @param tickets // amount of tickets * @param fine // the cost of the fine * @return the penalty cost */ public static double calcPenalty(int tickets, double fine) { double penalty = 0; if(tickets >= 2) { penalty = fine * 1/3; } return penalty; } /** * The calcReckless method calculates the reckless driving charge based on the difference between y and x * @param y // the speed the driver was going * @param x // the speed limit * @return the cost of the reckless driving charge */ public static double calcReckless(int y, int x) { double reckless = 0; int difference = y - x; if(difference > 40) { difference -= 40; reckless = difference * 150; } return reckless; } }
Scenario: The town of Speedtrap, Oklahoma, gives out lots of speeding tickets. Speedtrap just passed a NEWER speeding ticket fine ordinance. The new fine structure will be
$200 over by less than 10 mph
$300 10 or more, less than 20
$400 20 or more, less than 30
$500 30 or more
The penalty for getting lots of tickets is now
2-5 previous tickets 1/3
6-10 previous tickets 1/2
More than 10 previous tickets 2/3
The reckless driving fine kicks in if you are more than 1/3 over the limit. So in a 30 mph zone, it would kick in at 40 mph. In a 45 mph zone, it would kick in at 60 mph. If the division doesnt work out, the cutoff is the next highest integer for example in a 35 mph zone, the cutoff would be 47. Because its now going to be implemented at lower speeds, the fee per mile over that cutoff is lower at $99.50 per mph over the cutoff.
If drivers are in a workzone or a school zone, they pay a 2/3 penalty on top of their total fine. This is implemented after everything else is calculated. The officer will have to answer yes or no on this.
The town has also gotten complaints of people getting fines when they werent going over the speed limit. That needs to be fixed. If people arent going over the limit, they shouldnt get a fine.
You will be modifying the assigned submission to implement these changes. Follow the guidelines as presented in the spreadsheet that makes those assignments. Amend the output to provide one line per category
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started