Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS1 Decisions 100-point Version Speeding Ticket Lab Problem Description: The Plano Police Department needs your help in calculating the cost of speeding tickets. The minimum

CS1 Decisions 100-point Version Speeding Ticket Lab Problem Description: The Plano Police Department needs your help in calculating the cost of speeding tickets. The minimum cost of a speeding ticket is $50. If the driver is in a school zone, an additional $15 for each mile per hour over the speed limit is assessed; otherwise, an additional $7 for each mile per hour over the speed limit is assessed. Whenever the driver is caught driving more than 30 miles per hour over the speed limit, an additional $175 is added to the cost of the speeding ticket. Implement the SpeedingTicket class to compute the cost of a speeding ticket based on the speed traveled, the posted speed limit, and whether or not the driver was in a school zone. Assume the program is only being used when someone is actually speeding. The SpeedingTicket class has been started for you. Copy the following folder to your CS1\Labs directory. S:\Templates\Computer Science\CS1\Labs\Unit 05 Speeding Ticket Lab You will need to add your heading to the top of the file and add meaningful comments in the main and above the calcTicket method. SpeedingTicket Class Description You work will be divided between 2 methods. In the main method, you will perform the keyboard input, call the calcTicket method to calculate the ticket cost, and then display the ticket information. Above the main method: 1. It is important not to have magic numbers in your code. If any of the costs or rates needed to change, changes would be made only to the constants, and the remainder of the code would not require change. Define the following static constants above the main method. They may be private or public. You must use these in the calcTicket method. o An integer to represent the minimum cost of a ticket ($50) o An integer to represent the standard rate per excess speed ($7) o An integer to represent the school zone rate per excess speed ($15) o An integer to represent the excessive speed threshold (30); drivers traveling more than 30 miles over the speed limit incur an additional cost o An integer to represent the excessive speed cost ($175); drivers traveling more than the excessive speed threshold incur an additional cost of $175 main method: 1. Input the following information from standard input (the keyboard): o Drivers name, stored as a string o Speed traveled, stored as an integer o Speed limit, stored as an integer o Whether or not the driver was in a school zone (yes or no, stored as a string) 2. Call the calcTicket method to calculate the ticket cost. Store the results in an appropriate variable. 3. Display the drivers information and ticket cost according to the sample execution. Your output should be formatted in the same fashion as the sample execution! The driving speed, speed limit, and school zone data is right aligned. calcTicket method: 1. Calculate the cost of the ticket as an integer based on the formula described in the problem description. When determining which rate to use for the excess speed (standard or school zone rate), ignore any case differences. The replies YES, Yes, and yes should all be acceptable. You may assume any reply other than yes is a no. 2. Return the calculated cost. (Replace the existing return statement.)

ive done this much :

/* heading goes here

* Ava kang

*01/20/2023

*/

import java.util.Scanner;

public class SpeedingTicket

{

/** Define your static constants here */

public static final int MIN_COST = 50;

public static void main(String[] args)

{

Scanner scan = new Scanner(System.in);

System.out.print("Enter driver's name:");

String name = scan.nextLine();

System.out.print("Enter driver's speed:");

int speed = scan.nextInt();

System.out.print("Enter speed limit:");

int limit = scan.nextInt();

System.out.print("Was driver in school zone?");

String zone = scan.next();

}

/**

*/

// Calculate cost

public static int calcTicket(int speedDriving, int speedLimit, String schoolZone)

{

double total;

if(actualSpeed > (speedLimit + 5.0))

{

//if yes, multiplying $15 for each mile over the speedLimit

total+=15.0*(actualSpeed - speedLimit);

//reading if speeding happened in a school zone

isSchoolZone=scanner.next().charAt(0);

//if yes, doubling the ticket

if(isSchoolZone=='Y'){

total+ = total;

return minTicket;

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

Describe four issues that affect career management

Answered: 1 week ago