Write a solution to Programming Challenges problem #8 -- the Parking Ticket Simu
ID: 3549789 • Letter: W
Question
Write a solution to Programming Challenges problem #8 -- the Parking Ticket Simulator (p. 558 of the textbook).
For this problem you will need to write and submit the four Java classes described in that problem. Write one class per file
NOTE: The UML diagram below show that the ParkingTicket class' calculateFine method's return type is void. You can make this a return type of double if you wish.
Below is a sample usage of those classes. When run with your classes, the code below should generate the following output:
Output
TICKET ISSUED:
Car Data:
Make: Ford
Model: 1986
Color: Grey
License Number: BAC4455
Minutes Parked: 85
Officer Data:
Name: John Doe
BadgeNumber: 9932
Fine: $25.00
Sample Usage
Write a solution to Programming Challenges problem #8 -- the Parking Ticket Simulator (p. 558 of the textbook).
For this problem you will need to write and submit the four Java classes described in that problem. Write one class per file
NOTE: The UML diagram below show that the ParkingTicket class' calculateFine method's return type is void. You can make this a return type of double if you wish.
Below is a sample usage of those classes. When run with your classes, the code below should generate the following output:
Output
TICKET ISSUED:
Car Data:
Make: Ford
Model: 1986
Color: Grey
License Number: BAC4455
Minutes Parked: 85
Officer Data:
Name: John Doe
BadgeNumber: 9932
Fine: $25.00
Sample Usage
public class TestParkingTicket
{
public static void main(String[] args)
{
// This 1986 Ford was parked for 85 minutes
ParkedCar car = new ParkedCar("Ford", "1986", "Grey",
"BAC4455", 85);
// The meter had 30 minutes on it
ParkingMeter meter = new ParkingMeter(30);
PoliceOfficer officer = new PoliceOfficer("John Doe",
"9932");
// The officer is on patrol and sees the parked car
// and the meter.
// If the car was parked for a longer time than was
// on the meter, then the "patrol" method will
// issue a ticket.
// If there was enough time on the meter to cover the
// time the car was parked, then no ticket is
// issued (i.e., a null reference is returned).
ParkingTicket ticket = officer.patrol(car, meter);
// If no ticket was issued, then "ticket" is null
if (ticket == null)
System.out.println("No crimes committed!");
else
{
System.out.println("TICKET ISSUED: ");
System.out.println(ticket);
}
}
}
Here are the UML class diagrams for the classes:
Explanation / Answer
The class with main method is same as the one given in the question
package com.chegg.parking;
public class ParkedCar {
private String make;
private String model;
private String color;
private String liscenceNo;
private int minutesParked;
public ParkedCar(String make, String model, String color,
String liscenceNo, int minutesParked) {
super();
this.make = make;
this.model = model;
this.color = color;
this.liscenceNo = liscenceNo;
this.minutesParked = minutesParked;
}
public ParkedCar(ParkedCar car2){
}
public String getMake() {
return make;
}
public void setMake(String make) {
this.make = make;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getLiscenceNo() {
return liscenceNo;
}
public void setLiscenceNo(String liscenceNo) {
this.liscenceNo = liscenceNo;
}
public int getMinutesParked() {
return minutesParked;
}
public void setMinutesParked(int minutesParked) {
this.minutesParked = minutesParked;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(" make:");
builder.append(make);
builder.append(" model:");
builder.append(model);
builder.append(" color:");
builder.append(color);
builder.append(" liscenceNo:");
builder.append(liscenceNo);
builder.append(" minutesParked:");
builder.append(minutesParked);
return builder.toString();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.