Question
PoliceOfficer Class additional information - The patrol method looks at the number of minutes a car has been parked and the number of minutes purchased.
PoliceOfficer Class additional information
- 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.
Create a public method of the ParkingTicket class named patrol. This method will accept a ParkedCar object and a ParkingMeter object
Ex: public Course java(Instructor inst, Textbook text)
Assign the ParkingTicket object ticket the value of null
Ex: Textbook text = null;
Get the minutes parked over the amount purchased.
Declare an integer variable names illegalMinutes
illegalMinutes = car objects minutes parked the meter objects minutes purchased
Determine whether the car is illegally parked.
If the illegalMinutes are greater than 0, then the car is illegally parked and a ticket must be issued. Assign the ticket object a new ParkingTicket sending over the car object, this policer officer and the illegal minutes
Return the ticket
ParkingTicket Additional Information
In the constructor call the calculate fine method
Create a public method named ParkingTicket that will accept a ParkedCar object, a PoliceOfficer Object and an integer value for minutes. Assign each to the correct instance variables, instance objects, call the calculateFine method.
Create a public method named ParkingTicket which will accept a ParkingTicket object. Assign the ticket to the car object. Assign the ticket to the officer object, assign the ticket to the fine .
Ex: myCar = ticket.myCar
Create a calculate fine method.
Declare a double variable for hours
Create a formula for hours = minutes /60
Declare an integer variable for hours , convert the double hours to integer . Ex: (int)hours
Create an if statement to round up any minutes to an hour, If the double hours the integer hours is greater than 0 add 1 to integer hours
Assign the fine variable the base fine amount
Add any additional fine by adding the integer hours * hourly fine to the fine variable
Create a setCar method which accepts a ParkedCar object and sets it = to the car instance object. Do the same for the setOfficer
Create a getCar method that will return the car object as a ParkedCar . Do the same for the getOfficer method
Main Class
Create a ParkedCar object with the following information 2018, Infinity, Red, 60, 147RHZM
Create a ParkingMeter object with 60 minutes purchased.
Create a PoliceOfficer object with the following information Joe Friday, 4788
Create a ParkingTicket Object assign it to the office object patrol method sending the car and meter object
Create an If statement to determin if a ticket was written
If the ticket is not equal to null output the ticket else print No ticket issued
THats the UMl for four classes
first-
public class ParkingTicket {
private Parkedcar car;
private PoliceOfficer Officer;
private double fine;
private int minutes;
private double BASE_FINE = 25.0;
private double HOURLY_FINE = 10.0;
public ParkingTicket(Parkedcar c, PoliceOfficer off, int min, double fn) {
car = c;
Officer = off;
minutes = min;
fine = fn;
}
public void setcalculateFine() {
}
public void setParkedcar(Parkedcar c) {
car = c;
}
public void setPoliceOfficer(PoliceOfficer Off) {
Officer = Off;
}
public void setFine(double fn) {
fine = fn;
}
public void setminutes(int min) {
minutes = min;
}
public Parkedcar getParkedcar() {
return car;
}
public PoliceOfficer getPoliceOfficer() {
return Officer;
}
secnd-
public class Parkedcar {
private String make;
private String model;
private String color;
private String LicenseNumber;
private int minutesParked;
public Parkedcar() {
make = null;
model = null;
color = null;
LicenseNumber = null;
minutesParked = 0;
}
public Parkedcar(String mk, String mod, String col, String lic, int min)
{
make = mk;
model = mod;
color = col;
LicenseNumber = lic;
minutesParked = min;
}
public void setmake(String mk) {
make = mk;
}
public void setmodel(String mod) {
model = mod;
}
third-
public class PoliceOfficer {
private String name;
private String badgeNumber;
//private Parkedcar car;
//private PoliceOfficer Officer2;
public PoliceOfficer() {
name = null;
badgeNumber = null;
}
public PoliceOfficer(String n, String bn) {
name = n;
badgeNumber = bn;
}
public void setName(String n) {
name = n;
}
public void setBadgeNumber(String bn) {
badgeNumber = bn;
}
public String getName() {
return name;
}
public String getBadgeNumber() {
return badgeNumber;
}
fourth-
public class Parkingmeter {
private int minutesPurchased;
public Parkingmeter() {
minutesPurchased = 0;
}
public Parkingmeter(int m) {
minutesPurchased = m;
}
public void setminutesPurchased(int m) {
minutesPurchased = m;
}
public int getminutesPurchased() {
return minutesPurchased;
}
}
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