Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Define a class called PoliceDatabase with the following instance variables: vehicles infractions an array storing all infractions that have ever been given to

In Java Define a class called PoliceDatabase with the following instance variables: vehicles infractions an array storing all infractions that have ever been given to drivers numInfractions - an int that keeps track of how many infractions there are in the database

issueInfraction(String license, float amount, String description, Date date) which causes the driver with the given license to receive an infraction for the given amount and description (i.e., reason) on the given date ... updating the database as necessary. This method MUST return the Infraction object created. If the number of infractions has reached its limit in the database, then nothing is to be done.

hasOutstandingInfractions(Driver d) which returns a boolean with a value of true if the driver has any infractions that have not been paid yet, otherwise it should return false.

shouldStopVehicle(String plate) which decides whether or not the police should pull this vehicle over. It should return a boolean with a value of true if and only if the vehicle has been reportedStolen, or if the vehicle's owner has at least one outstanding infraction (you MUST make use of the method hasOutstandingInfractions()). Otherwise, the method should return false.

showInfractionsFor(String license) which displays a list of all infractions that the driver with this license ID has incurred showing (on successive lines) the driver's infractions and then finish with the total number of outstanding infractions. Here is the format you should use:

$100.00 Infraction on Sat Mar 03 11:55:00 EST 1990 [PAID IN FULL]

$250.00 Infraction on Tue Oct 06 09:22:00 EDT 1992 [PAID IN FULL]

$280.00 Infraction on Wed Aug 07 09:05:00 EDT 1996 [PAID IN FULL]

$300.00 Infraction on Fri Mar 03 12:15:00 EST 2000 [OUTSTANDING]

$350.00 Infraction on Mon Feb 01 02:04:00 EST 2010 [OUTSTANDING]

Total outstanding infractions = 2

cleanDrivers() which returns an Driver[ ] of all drivers who have never had any infractions. The array should have a length corresponding exactly to the number of clean drivers (i.e., no nulls). showInfractionReport() which lists information about all drivers who have had at least one infraction. Each line in the list should show a drivers name (formatted to take 20 spaces using the String.format()) followed by the number of infractions that they received and the total amount for all infractions that they have already paid (formatted as shown) as follows:

The Driver, Infractions and Vehicle classes are as given:

import java.util.Date; public class Infraction { float amount; String description; Date dateIssued; boolean outStanding = true; Driver driver; public Infraction(float a, String des, Date d){ this.amount = a; this.description = des; this.dateIssued = d; } public Infraction(){ this.amount = 100.00f; this.description = "infraction"; this.dateIssued = new Date(); } public String toString(){ if(outStanding == false){ return "$" + String.format("%.2f", amount) + "Infraction on " + dateIssued + "[PAID IN FULL]"; } else{ return "$" + String.format("%.2f", amount) + "Infraction on " + dateIssued + "[OUTSTANDING]"; } } public void pay(){ System.out.println("Infraction paid for"); outStanding = false; } } 
public class Driver { String license; String name; String street; String city; String province; public Driver(String license, String name, String street, String city, String province) { this.license = license; this.name = name; this.street = street; this.city = city; this.province = province; } public Driver() { this("", "", "", "", ""); } @Override public String toString() { return "#" + license + " " + name + " " + "living at " + street + ", " + city + ", " + province; } } 
public class Vehicle { String make; String model; int year; String color; String plate; Driver owner; boolean reportedStolen; public Vehicle(String make, String model, int year, String color, String plate) { this.make = make; this.model = model; this.year = year; this.color = color; this.plate = plate; owner = new Driver(); reportedStolen = false; } public Vehicle() { this("", "", 0, "", ""); } @Override public String toString() { return "A " + color + " " + year + " " + make + " " + model + " with plate " + plate; } } 

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago