Question: Chapter 8: Programming Challenge #8 - Parking Ticket Simulator - UML class diagram // need - Pseudo-Code for each class // need - Java Doc
Chapter 8: Programming Challenge #8 - Parking Ticket Simulator
- UML class diagram // need
- Pseudo-Code for each class // need
- Java Doc //need
I have the code written Just need above requirement
******************************************************************************************************
/** * Class to simulate a police officer. * He has a name and badge number and * knows how to inspect a parked car * and a parking meter. */ public class PoliceOfficer { private String name; private String badgeNumber;
/** * This Constructor Initalizes police name and BadgeNumber. * @param name Name of the Police Officer * @param badgeNumber badge number of the Police Officer */ public PoliceOfficer(String name, String badgeNumber) { this.name = name; this.badgeNumber = badgeNumber; }
/** * This Constructor Initalizes other police name * and BadgeNumber for car 2 * @param other Name of the Police Officer and the badgenumber */ public PoliceOfficer(PoliceOfficer other) { this.name = other.name; this.badgeNumber = other.badgeNumber; }
/** *The ParkingTicket method inspects *if a car needs to be fined or not *@return The Fine if its over the parking limit or null if its not */ public ParkingTicket inspect(ParkedCar car, ParkingMeter meter) { if (car.getMinutesParked() > meter.getMinutesPurchased()) { return new ParkingTicket(this,car,meter); } return null; }
/** toString method @return A string containing the police officer information. */ public String toString() { return "Officer Name: " + name + " " + "Badge Number: " + badgeNumber; } }
******************************************************************************************************
/** * Class to test the Parking Ticket classes */ public class ParkingTicketSimulator { public static void main(String [] args) { ParkedCar car = new ParkedCar("Hyundai","Sonata","Blue","T08BOD",160); ParkingMeter meter = new ParkingMeter(10); PoliceOfficer officer = new PoliceOfficer("Johnny Lee","GVGC023"); ParkingTicket ticket = officer.inspect(car,meter); if (ticket != null) { System.out.println(ticket + " "); } else { System.out.println("No ticket! "); }
ParkedCar car2 = new ParkedCar("Tesla","Model 3","Black","Fancy",735); ParkingMeter meter2 = new ParkingMeter(60); PoliceOfficer officer2 = new PoliceOfficer("Jay CoolGuy","XYZ789"); ParkingTicket ticket2 = officer2.inspect(car2,meter2); if (ticket2 != null) { System.out.println(ticket2); } else { System.out.println("No ticket!"); } } }
******************************************************************************************************
/** * Class to simulate a parked car. * It knows car make, model, color, * license number and minutes parked. */ public class ParkedCar { private String make; //Car Make private String model; //Car Model private String color; //Car Color private String licenseNumber; //Car License Number private int minutesParked; //Minutes Purchased
/** * This Constructor Initalizes Parked Car make, model, * color,licensenumber, minutes purchased * @param make Make of the car * @param model Model of the car * @param color Color of the car * @param licenseNumber License PLate of the car * @param minutes Minutes Purchased at the meter */ public ParkedCar(String make, String model, String color, String licenseNumber, int minutes) { this.make = make; this.model = model; this.color = color; this.licenseNumber = licenseNumber; this.minutesParked = (minutes > 0) ? minutes : 0; }
/** * This Constructor Initalizes Parked Car 2 * @param other other make, model, * color,licensenumber, minutes purchased */ public ParkedCar(ParkedCar other) { this.make = other.make; this.model = other.model; this.color = other.color; this.licenseNumber = other.licenseNumber; this.minutesParked = other.minutesParked; }
/** The getMake method returns the make of the car. @return The make of the car. */ public String getMake() { return make; }
/** The getModel method returns the model of the car. @return The model of the car. */ public String getModel() { return model; }
/** The getColor method returns the Color of the car. @return The Color of the car. */ public String getColor() { return color; }
/** The getLicenseNumber method returns the License Plate. @return The License plate. */ public String getLicenseNumber() { return licenseNumber; }
/** The getMinutesParked method returns the minutes parker. @return The minutes Parked. */ public int getMinutesParked() { return minutesParked; }
/** toString method @return A string containing the parked car information. */ public String toString() { return "Make: " + make + " " + "Model: " + model + " " + "Color: " + color + " " + "License Number: " + licenseNumber + " " + "Minutes Parked: " + minutesParked; } }
******************************************************************************************************
/** * Class to simulate a parking meter. * It know how many minutes were purchased. */ public class ParkingMeter { private int minutesPurchased;
/** * This Constructor Initalizes minutesPurchased * @param minutes minutesPurchased */ public ParkingMeter(int minutes) { minutesPurchased = (minutes > 0) ? minutes : 0; }
/** * This Constructor Initalizes minutesPurchased * for car #2 * @param other minutesPurchased */ public ParkingMeter(ParkingMeter other) { this.minutesPurchased = other.minutesPurchased; }
/** The getMinutesPurchased method returns the minutes purchased. @return The minutes Purchased. */ public int getMinutesPurchased() { return minutesPurchased; }
/** toString method @return A string containing the minutes purchased information. */ public String toString() { return "Minutes Purchased: " + minutesPurchased; } }
******************************************************************************************************
import java.text.DecimalFormat; //Decimal Format /** * ParkingTicketClass to simulate a parking ticket */ public class ParkingTicket { private static int count = 0; private PoliceOfficer officer; private ParkedCar car; private ParkingMeter meter; private int fine;
/** * ParkingTicketClass to simulate a parking ticket. * To Output the name of the officer * To calculate the meter reading and generate fines where needed * @param officer Officer Name and Badge number * @param car type of the car parked * @param meter Meter reading to find out how much the car needs to be fined */ public ParkingTicket(PoliceOfficer officer, ParkedCar car, ParkingMeter meter) { ++count; //Count of the Parking tickets this.officer = officer; this.car = car; this.meter = meter; int hoursOver = (int)Math.ceil((car.getMinutesParked() - meter.getMinutesPurchased())/60.0); fine = 25 + 10*(hoursOver-1); }
/** toString method @return A string containing the parking ticket information. */ public String toString() { DecimalFormat df = new DecimalFormat("$###.00"); return "______________ Parking Ticket #" + count + " " + car + " " + meter + " Fine: " + df.format(fine) + " " + officer; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
