Question
Parking Ticket Simulator For this assignment you will have a set of classes that work together to simulate a police officer issuing a parking ticket.
Parking Ticket Simulator For this assignment you will have a set of classes that work together to simulate a police officer issuing a parking ticket. These are the following classes
public class PoliceOfficer { private String name; // Officer's name private String badgeNumber; // Badge number /** Constructor @param n The officer's name. @param bn The officer's badge number. */ public PoliceOfficer(String n, String bn) { name = n; badgeNumber = bn; } /** Copy constructor @param officer2 The PoliceOfficer object to copy. */ public PoliceOfficer(PoliceOfficer officer2) { name = officer2.name; badgeNumber = officer2.badgeNumber; } /** setName method @param n The officer's name. */ public void setName(String n) { name = n; } /** setBadgeNumber method @param n The officer's badge number. */ public void setBadgeNumber(String b) { badgeNumber = b; } /** getName method @return The officer's name. */ public String getName() { return name; } /** getBadgeNumber method @return The officer's badge number */ public String getBadgeNumber() { return badgeNumber; } /** The patrol method looks at the number of minutes a car has been parked and the number of minutes purchased. If the minutes parked is greater than the minutes purchased, a ParkingTicket object is returned. Otherwise the method returns null. @param car A ParkedCar object. @param meter A ParkingMeter object. @return A ParkingTicket object if a violation occurred, null otherwise. */ public ParkingTicket patrol(ParkedCar car, ParkingMeter meter) { ParkingTicket ticket = null; // To reference the ticket // Get the minutes parked over the amount purchased. int illegalMinutes = car.getMinutesParked() - meter.getMinutesPurchased(); // Determine whether the car is illegally parked. if (illegalMinutes > 0) { // Yes, it is illegally parked. ticket = new ParkingTicket(car, this, illegalMinutes); } // Return the ticket, if any. return ticket; } /** toString method @return A string stating the officer's name and badge number. */ public String toString() { // Build a state string. String str = String.format("Name: %s " + "BadgeNumber: %s ", name, badgeNumber); // Return the String. return str; } }
===============================================
public class ParkingTicket { private ParkedCar car; // The parked car private PoliceOfficer officer; // The police officer private double fine; // The parking fine private int minutes; // Minutes illegally parked // Constant for the base fine. public final double BASE_FINE = 25.0; // Constant for the additional hourly fine. public final double HOURLY_FINE = 10.0; /** Constructor @param aCar A ParkedCar object. @param anOfficer A PoliceOfficer object. @param min Minutes illegally parked. */ public ParkingTicket(ParkedCar aCar, PoliceOfficer anOfficer, int min) { // Make a copy of the object referenced by aCar. car = new ParkedCar(aCar); // Make a copy of the object referenced by anOfficer. officer = new PoliceOfficer(anOfficer); // Assign the minutes illegally parked. minutes = min; // Calculate the fine. calculateFine(); } /** Copy constructor @param ticket2 A ParkingTicket object to copy. */ public ParkingTicket(ParkingTicket ticket2) { // Make a copy of the object referenced by aCar. car = new ParkedCar(ticket2.car); // Make a copy of the object referenced by anOfficer. officer = new PoliceOfficer(ticket2.officer); // Assign the fine. fine = ticket2.fine; } /** calculateFine method This method calculates the amount of the parking fine. */ private void calculateFine() { // Get the time parked in hours. double hours = minutes / 60.0; // Get the hours as an int. int hoursAsInt = (int)hours; // If there was a portion of an hour, round up. if ((hours - hoursAsInt) > 0) hoursAsInt++; // Assign the base fine. fine = BASE_FINE; // Add the additional hourly fines. fine += (hoursAsInt * HOURLY_FINE); } /** setCar method @param c A ParkedCar object. */ public void setCar(ParkedCar c) { // Make a copy of the object referenced by c. car = new ParkedCar(c); } /** setOfficer method @param o A PoliceOfficer object. */ public void setOfficer(PoliceOfficer o) { // Make a copy of the object referenced by o. officer = new PoliceOfficer(o); } /** getCar method @return A copy of this object's car field. */ public ParkedCar getCar() { // Return a copy of the car object. return new ParkedCar(car); } /** getFine method @return The amount of the fine. */ public double getFine() { return fine; } /** getOfficer method @return A copy of this object's officer field. */ public PoliceOfficer getOfficer() { // Return a copy of the officer object. return new PoliceOfficer(officer); } /** toString method @return A string stating data about the car, the police officer, and the parking violation. */ public String toString() { // Build a state string. String str = String.format("Car Data: " + "%s " + "Officer Data: " + "%s " + "Minutes Illegally Parked: %d " + "Fine: $%,.2f ", car, officer, minutes, fine); // Return the string. return str; } }
============================
public class ParkingMeter { private int minutesPurchased; // Minutes purchased /** Constructor @param m The number of minutes purchased. */ public ParkingMeter(int m) { minutesPurchased = m; } /** setMinutesPurchased method @param m The number of minutes purchased. */ public void setMinutesPurchased(int m) { minutesPurchased = m; } /** getMinutesPurchased method @return The number of minutes purchased. */ public int getMinutesPurchased() { return minutesPurchased; } }
===========================================
public class ParkedCar { private String make; // The car's make private String year; // The car's model private String color; // The car's color private String licenseNumber; // The car's license number private int minutesParked; // Minutes parked /** Constructor @param mk The car's make. @param mod The car's model. @param col The car's color. @param lic The car's license number. @param min The number of minutes parked. */ public ParkedCar(String mk, String yr, String col, String lic, int min) { make = mk; year = yr; color = col; licenseNumber = lic; minutesParked = min; } /** Copy constructor @param car2 A reference to a ParkedCar object to copy. */ public ParkedCar(ParkedCar car2) { make = car2.make; year = car2.year; color = car2.color; licenseNumber = car2.licenseNumber; minutesParked = car2.minutesParked; } /** setMake method @m The car's make. */ public void setMake(String m) { make = m; } /** setModel method @m The car's model. */ public void setModel(String yr) { year = yr; } /** setColor method @c The car's color. */ public void setColor(String c) { color = c; } /** setLicenseNumber method @lic The car's license number. */ public void setLicenseNumber(String lic) { licenseNumber = lic; } /** setMinutesParked method @m The number of minutes parked. */ public void setMinutesParked(int m) { minutesParked = m; } /** getMake method @return The car's make. */ public String getMake() { return make; } /** getModel method @return The car's model. */ public String getYear() { return year; } /** getColor method @return The car's color. */ public String getColor() { return color; } /** getLicenseNumber method @return The car's license number. */ public String getLicenseNumber() { return licenseNumber; } /** getMinutesParked method @return The number of minutes parked. */ public int getMinutesParked() { return minutesParked; } /** toString method @return A string stating the car's make, model, color, license number, and minutes parked. */ public String toString() { // Build a state string. String str = String.format("Make: %s " + "Year: %s " + "Color: %s " + "License Number: %s " + "Minutes Parked: %d ", make, year, color, licenseNumber, minutesParked); // Return the string. return str; } }
=====================================
Ticket should look something like this for 5 diffrent people all in the same output
Ticket for 2007 Honda
Car Data:
Make: Honda
Year: 2007
Color: Black
License Number: VA12345
Minutes Parked: 125
Officer Data:
Name: Smith
BadgeNumber: 2930
Minutes Illegaly Parked: 65
Fine: $45.00
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