Comp 1006 Assignment 3 solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

In this assignment, you will simulate a police database that keeps track of a driver’s history with respect to the number of times they were pulled over and ticketed for an infraction (i.e., a driving violation). The database will make use of Arrays so as to allow many drivers, vehicles and infractions to be stored together in lists. We will design a very small system and test it with only a few cars and owners.

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 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 (hint…use 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 vehicle’s 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 vehicle’s 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.
____________________________________________________________________________________________

(3) 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