Question
Hey guys, I need help mostly with the part on More on the PoliceData class regarding the IssueInfractions part The Driver, Vehicle & Infraction Classes
Hey guys, I need help mostly with the part on "More on the PoliceData class" regarding the IssueInfractions part
The Driver, Vehicle & Infraction Classes Define a class called Driver that defines the following attributes: license - a String representing a driver's license ID (e.g. "L0678-67825-83940"); name - a String representing the name of the driver street - a String representing the street name and number for this driver (e.g., "12 Elm St."); city - a String representing the city in which this driver lives province - a String representing the province in which this driver lives Write the following in the Driver class: a proper constructor that takes 5 parameters for all 5 attributes in the order shown above a proper zero-parameter constructor that calls the first constructor with appropriate values a toString() method that returns a string in the following format: "#L0678-67825-83940 John Doe living at 12 Elm St., Ottawa, ON" Define a class called Vehicle that defines the following attributes: make - a string representing the company that made the vehicle (e.g., "Pontiac", "Honda", etc..) model - a string representing the model of the vehicle (e.g., "Grand Prix", "Civic", etc..) year an int representing the year of the vehicle (e.g., 2004 etc..) color - a string representing the color of the vehicle (e.g., "red", "blue" etc..) plate - a string representing the license plate of the vehicle (e.g., "X5T6Y8", "2FAST", etc..) owner - a Driver object representing the owner of the vehicle (e.g., John Doe from part 1) reportedStolen - a boolean indicating whether or not the vehicle has been reported as stolen Write the following in the Vehicle class: a proper constructor that takes 5 parameters for the first 5 attributes in the order shown above (assume new vehicles are not stolen and there is no owner yet). a proper zero-parameter constructor that calls the first constructor with appropriate values a toString() method that returns a string in the following format: "A blue 1998 Honda Civic with plate X5T6Y8" Define a class called Infraction (i.e., an infraction is a violation) that defines the following attributes: amount - a float indicating how much the fine was for this infraction description - a String describing the infraction (e.g., "Not stopping for red light") dateIssued - a Date representing the date and time at which the infraction occurred. You must import java.util.Date in order for your code to compile. outstanding - a boolean indicating whether or not the infraction was paid yet driver - a Driver object representing the driver that received the infraction Write the following in the Infraction class: a proper constructor that takes 3 parameters for the first 3 attributes in the order shown above a proper constructor that takes zero-parameters and calls the above constructor a toString() method that returns a string with the format below (use the String.format() method to format the amount to 2 decimal places and to display the date/time. The portion of the format string for displaying the date is %tc. If the infraction has been paid, it should state [PAID IN FULL] as shown, otherwise it should state [OUTSTANDING]): "$100.00 Infraction on Sun Jul 14 07:08:00 EDT 2002 [PAID IN FULL]" a method called pay() which pays the infraction (hintuse outstanding attribute) ____________________________________________________________________________________________ The PoliceDatabase Class Define a class called PoliceDatabase with the following instance variables: vehicles an array storing all vehicles in the database numVehicles - an int that keeps track of how many vehicles there are in the database drivers an array storing all drivers (i.e., people who drive vehicles) in the database numDrivers - an int that keeps track of how many drivers there are in the database 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 Write the following in the PoliceDatabase class: three static constants to represent the database size limits so that at most 2000 drivers, at most 1000 vehicles and at most 800 infractions are allowed to be added to the database. Make sure that the rest of your code adheres to these exact limits. a zero-parameter constructor that initializes all the arrays properly a registerDriver(Driver aDriver) method which takes aDriver object as a parameter and then registers (i.e., remembers for later) the driver in the database ... assuming that the database is not full, otherwise the driver is not to be registered. a registerVehicle(Vehicle aVehicle, String license) method which takes aVehicle object as a parameter and the license ID of a driver who owns the vehicle (i.e., this is not the license plate of the vehicle) and then registers the vehicle in the database, making sure to also store the vehicles owner properly ... assuming that the database is not full, otherwise the vehicle is not to be registered. a unregisterVehicle(String plate) method which takes a vehicles plate number as a parameter and then removes the vehicle from the database without altering the order of the vehicles currently in the database and without leaving any gaps in the array. If the plate is not in the database, then nothing is to be done. a reportStolen(String plate) method which records that the vehicle with the given plate number has been stolen. If the plate is not in the database, then nothing is to be done. a changeOwner(String plate, String license) method which updates the database by changing the owner information for the vehicle with the given plate to the driver with the given license ID (i.e., this second parameter is not the license plate of the vehicle). If the plate or license is not in the database, then nothing is to be done. ____________________________________________________________________________________________ Some Testing to Make Sure That It All Works So Far Copy (cut and paste from the file, do not re-type) the example() method on the next page into your PoliceDatabase class. It is a method that builds and returns a PoliceDatabase object with some drivers and vehicles already registered. Re-compile to make sure that you have no errors. public static PoliceDatabase example() { // Register all drivers and their vehicles PoliceDatabase pdb = new PoliceDatabase(); pdb.registerDriver(new Driver("L1567-34323-84980", "Matt Adore", "1323 Kenaston St.", "Gloucester", "ON")); pdb.registerDriver(new Driver("L0453-65433-87655", "Bob B. Pins", "32 Rideau Rd.", "Greely", "ON")); pdb.registerDriver(new Driver("L2333-45645-54354", "Stan Dupp", "1355 Louis Lane", "Gloucester", "ON")); pdb.registerDriver(new Driver("L1234-35489-99837", "Ben Dover", "2348 Walkley Rd.", "Ottawa", "ON")); pdb.registerDriver(new Driver("L8192-87498-27387", "Patty O'Lantern", "2338 Carling Ave.", "Nepean", "ON")); pdb.registerDriver(new Driver("L2325-45789-35647", "Ilene Dover", "287 Bank St.", "Ottawa", "ON")); pdb.registerDriver(new Driver("L1213-92475-03984", "Patty O'Furniture", "200 St. Laurant Blvd.", "Ottawa", "ON")); pdb.registerDriver(new Driver("L1948-87265-34782", "Jen Tull", "1654 Stonehenge Cres.", "Ottawa", "ON")); pdb.registerDriver(new Driver("L0678-67825-83940", "Jim Class", "98 Oak Blvd.", "Ottawa", "ON")); pdb.registerDriver(new Driver("L0122-43643-73286", "Mark Mywords", "3 Third St.", "Ottawa", "ON")); pdb.registerDriver(new Driver("L6987-34532-43334", "Bob Upandown", "434 Gatineau Way", "Hull", "QC")); pdb.registerDriver(new Driver("L3345-32390-23789", "Carrie Meehome", "123 Thurston Drive", "Kanata", "ON")); pdb.registerDriver(new Driver("L3545-45396-88983", "Sam Pull", "22 Colonel By Drive", "Ottawa", "ON")); pdb.registerDriver(new Driver("L1144-26783-58390", "Neil Down", "17 Murray St.", "Nepean", "ON")); pdb.registerDriver(new Driver("L5487-16576-38426", "Pete Reedish", "3445 Bronson Ave.", "Ottawa", "ON")); pdb.registerVehicle(new Vehicle("Honda", "Civic", 2015, "yellow", "W3EW4T"), "L0453-65433-87655"); pdb.registerVehicle(new Vehicle("Pontiac","Grand Prix",2007,"dark green","GO SENS"), "L0453-65433-87655"); pdb.registerVehicle(new Vehicle("Mazda", "RX-8", 2004, "white", "OH YEAH"), "L2333-45645-54354"); pdb.registerVehicle(new Vehicle("Nissan","Altima",2017,"bergundy", "Y6P9O7"), "L1234-35489-99837"); pdb.registerVehicle(new Vehicle("Saturn", "Vue", 2002, "white", "9R6P2P"), "L2325-45789-35647"); pdb.registerVehicle(new Vehicle("Honda", "Accord", 2018, "gray", "7U3H5E"), "L2325-45789-35647"); pdb.registerVehicle(new Vehicle("Chrysler", "PT-Cruiser", 2006, "gold", "OLDIE"), "L2325-45789-35647"); pdb.registerVehicle(new Vehicle("Nissan", "Cube", 2010, "white", "5Y6K8V"), "L1948-87265-34782"); pdb.registerVehicle(new Vehicle("Porsche", "959", 1989, "silver", "CATCHME"), "L0678-67825-83940"); pdb.registerVehicle(new Vehicle("Kia", "Soul", 2018, "red", "J8JG2Z"), "L0122-43643-73286"); pdb.registerVehicle(new Vehicle("Porsche", "Cayenne", 2014, "black", "EXPNSV"), "L6987-34532-43334"); pdb.registerVehicle(new Vehicle("Nissan", "Murano", 2010, "silver", "Q2WF6H"), "L3345-32390-23789"); pdb.registerVehicle(new Vehicle("Honda", "Element", 2008, "black", "N7MB5C"), "L3545-45396-88983"); pdb.registerVehicle(new Vehicle("Toyota", "RAV-4", 2010, "green", "R3W5Y7"), "L3545-45396-88983"); pdb.registerVehicle(new Vehicle("Toyota", "Celica", 2006, "red", "FUNFUN"), "L5487-16576-38426"); return pdb; } Create the following class as a test program and make sure that it produces the proper output: import java.util.GregorianCalendar; public class PoliceDatabaseTestProgram { public static void main(String args[]) { PoliceDatabase pdb = PoliceDatabase.example(); System.out.println("Here are the drivers:"); for (int i=0; i More on the PoliceDatabase Class Add the following methods to the PoliceDatabase class: 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: Bob B. Pins: 1 infractions, total paid = $ 75.00 Ilene Dover: 4 infractions, total paid = $400.00 Jim Class: 5 infractions, total paid = $630.00 Bob Upandown: 1 infractions, total paid = $ 0.00 ... etc... ____________________________________________________________________________________________ Final Testing Define a class called PoliceDatabaseTestProgram2 as shown on the next page. Cut and paste the code do not re-type it. It would be a good idea to write blank methods for part 4 so that the test code compiles and runs. Then fill in the methods one at a time and test them. import java.util.GregorianCalendar; public class PoliceDatabaseTestProgram2 { public static void addInfractions(PoliceDatabase pdb) { pdb.issueInfraction("L0453-65433-87655", 75, "Illegal U-Turn", new GregorianCalendar(2010, 6, 14, 7, 8).getTime()).pay(); pdb.issueInfraction("L2325-45789-35647", 175, "Speeding in excess of 20km", new GregorianCalendar(2011, 2, 2, 14, 22).getTime()).pay(); pdb.issueInfraction("L2325-45789-35647", 75, "Illegal U-Turn", new GregorianCalendar(2012, 3, 22, 4, 34).getTime()).pay(); pdb.issueInfraction("L2325-45789-35647", 150, "Wrong way up 1-way street", new GregorianCalendar(2014, 6, 14, 8, 2).getTime()).pay(); pdb.issueInfraction("L2325-45789-35647", 500, "Running red light", new GregorianCalendar(2017, 9, 12, 5, 15).getTime()); pdb.issueInfraction("L0678-67825-83940", 100, "Failure to signal", new GregorianCalendar(2008, 2, 3, 11, 55).getTime()).pay(); pdb.issueInfraction("L0678-67825-83940", 250, "Speeding in excess of 30km", new GregorianCalendar(2010, 9, 6, 9, 22).getTime()).pay(); pdb.issueInfraction("L0678-67825-83940", 280, "Speeding in excess of 30km", new GregorianCalendar(2015, 7, 7, 9, 5).getTime()).pay(); pdb.issueInfraction("L0678-67825-83940", 300, "Speeding in excess of 30km", new GregorianCalendar(2017, 11, 3, 12, 15).getTime()); pdb.issueInfraction("L0678-67825-83940", 350, "Speeding in excess of 30km", new GregorianCalendar(2018, 1, 1, 2, 4).getTime()); pdb.issueInfraction("L6987-34532-43334", 500, "Running red light", new GregorianCalendar(2017, 7, 2, 22, 17).getTime()); pdb.issueInfraction("L3545-45396-88983", 75, "Illegal U-Turn", new GregorianCalendar(2007, 3, 4, 20, 12).getTime()).pay(); pdb.issueInfraction("L3545-45396-88983", 175, "Speeding in excess of 20km", new GregorianCalendar(2011, 5, 4, 23, 25).getTime()).pay(); pdb.issueInfraction("L1144-26783-58390", 175, "Speeding in excess of 20km", new GregorianCalendar(2012, 10, 1, 19, 38).getTime()); pdb.issueInfraction("GARBAGE ID", 100, "Loving Java too much", new GregorianCalendar(2017, 11, 24, 19, 38).getTime()); } public static void main(String args[]) { // Make a new database and add some vehicles/owners etc.. PoliceDatabase pdb = PoliceDatabase.example(); addInfractions(pdb); System.out.println("Vehicles that should be stopped:"); for (int i=0; i
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