I need to create a program that does the following, but I\'ve done the most of i
ID: 3639717 • Letter: I
Question
I need to create a program that does the following, but I've done the most of it, but it won't work. Here's the program: I need to create a set of classes that ork together to simulate a police officer issuing a parking ticket. I need to design it with the following classes
(I get the error from the Police Officer Class, below the other classes}
- ParkedCar class: simulates a parked car
- This class knows the car's make, model, color, license number, and the number of minutes that the car has been parked.
{Here's what I've got}
public class ParkedCar {
private String make;
private String model;
private String color;
private String license;
private static int minutes;
public ParkedCar() {
}
public ParkedCar(String carMake, String carModel, String carColor, String carLicense, int carMinutes) {
make = carMake;
model = carModel;
color = carColor;
license = carLicense;
minutes = carMinutes;
}
public String getMake() {
return make;
}
public String getModel() {
return model;
}
public String getColor() {
return color;
}
public String getLicense() {
return license;
}
public static int getMinutes() {
return minutes;
}
public String toString() {
String string = "Make: " + make
+ " Model: " + model
+ " Color: " + color
+ " License Plate: " + license;
return string;
}
}
- ParkingMeter Class: simulates a parking meter.
- This classes only responsibility is to know the number of minutes of parking time that has been purchased.
public class ParkingMeter {
private static int minPurchased;
public ParkingMeter() {
}
public ParkingMeter(int carMinPurchased) {
minPurchased = carMinPurchased;
}
public static int getMinPurchased() {
return minPurchased;
}
public String toString() {
String string = "Minutes Purchased: " + minPurchased;
return string;
}
}
-ParkingTicket class: Simulates a parking ticket
Responsibilities:
- To report make, model, color, and license number of the illegally parked car.
- To report the amount of the fine which is $25 dollars for the first hour or part of the hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is parked.
- To report the name and badge number of the police officer issuing the ticket.
public class ParkingTicket {
private ParkedCar vehicle;
private PoliceOfficer copster;
private double fine;
private int minutes;
private double firstFine = 25;
private double moreFine = 10;
public ParkingTicket(ParkedCar car, PoliceOfficer cop, double guyFine, int mins) {
vehicle = car;
copster = cop;
fine = guyFine;
minutes = mins;
}
public void getTotalFine() {
int time = ParkedCar.getMinutes() - ParkingMeter.getMinPurchased();
if(time <= 60) {
fine = firstFine;
}
else {
fine = firstFine + moreFine * (time / 60);
}
}
public double getFirstFine() {
return firstFine;
}
public double getMoreFine() {
return moreFine;
}
public ParkedCar getVehicle() {
return vehicle;
}
public PoliceOfficer getCopster() {
return copster;
}
public int getMinutes() {
return minutes;
}
public double getFine() {
return fine;
}
}
- PoliceOfficer class: Simulates a police officer
Responsibilities:
- To know the police officer's name and badge number
- To examine a parked car object and a ParkingMeter object and determine whether the car's time has expired.
- To issue a parking ticket (generate a parkingTicket object) if the car's time has expired.
AND THIS IS WHERE I GET THE ERROR, AFTER I RUN My Demo
public class PoliceOfficer {
private String name;
private int badge;
private static double ticket;
public PoliceOfficer() {
}
public PoliceOfficer(String poName, int poBadge) {
name = poName;
badge = poBadge;
}
public String getName() {
return name;
}
public int getBadge() {
return badge;
}
static ParkingTicket search(ParkedCar car, ParkingMeter meter) {
int time = ParkedCar.getMinutes() - ParkingMeter.getMinPurchased();
if(ParkedCar.getMinutes() > ParkingMeter.getMinPurchased()) {
if(time <= 60) {
ticket = 25;
}
else {
ticket = 25 + (10 * (time/60));
}
}
return ticket;
}
}
And the Demo that connects the classes
public class ParkingCarDemo {
public static void main(String[] args) {
ParkedCar car = new ParkedCar("Honda", "Accord", "Black", "452-BTS", 78);
ParkingMeter meter = new ParkingMeter(60);
PoliceOfficer john = new PoliceOfficer("John Doe", 1337);
ParkingTicket ticket = PoliceOfficer.search(car, meter);
if(ticket != null) {
System.out.println(ticket);
}
else {
System.out.println("Car is not doing anything wrong!");
}
}
}
Explanation / Answer
Search method Police officeer is wrong... ( reurning double when asking to return Parkingticket Object)
public class PoliceOfficer {
private String name;
private int badge;
private double ticket;
public PoliceOfficer() {
}
public PoliceOfficer(String poName, int poBadge) {
name = poName;
badge = poBadge;
}
public String getName() {
return name;
}
public int getBadge() {
return badge;
}
public String toString() {
String string = "Officer : " + this.name
+ " Badge: " + badge
+ " Ticket: " + ticket;
return string;
}
public ParkingTicket search(ParkedCar car, ParkingMeter meter) {
PoliceOfficer po = new PoliceOfficer(this.name,this.badge);
int time = ParkedCar.getMinutes() - ParkingMeter.getMinPurchased();
if (ParkedCar.getMinutes() > ParkingMeter.getMinPurchased()) {
if (time <= 60) {
setTicket(25);
} else {
setTicket(25 + (10 * (time / 60)));
}
}
if( time <0)
return null;
return new ParkingTicket(car, po, getTicket(), time);
}
public double getTicket() {
return ticket;
}
public void setTicket(double ticket) {
this.ticket = ticket;
}
}
public class ParkingCarDemo {
public static void main(String[] args) {
ParkedCar car = new ParkedCar("Honda", "Accord", "Black", "452-BTS", 78);
ParkingMeter meter = new ParkingMeter(60);
PoliceOfficer john = new PoliceOfficer("John Doe", 1337);
ParkingTicket ticket = john.search(car, meter);
if (ticket != null) {
System.out.println(ticket.toString());
} else {
System.out.println("Car is not doing anything wrong!");
}
}
}
public class ParkingTicket {
private ParkedCar vehicle;
private PoliceOfficer copster;
private double fine;
private int minutes;
private double firstFine = 25;
private double moreFine = 10;
public ParkingTicket(ParkedCar car, PoliceOfficer cop, double guyFine, int mins) {
vehicle = car;
copster = cop;
fine = guyFine;
minutes = mins;
}
public void getTotalFine() {
int time = ParkedCar.getMinutes() - ParkingMeter.getMinPurchased();
if (time <= 60) {
fine = firstFine;
} else {
fine = firstFine + moreFine * (time / 60);
}
}
public double getFirstFine() {
return firstFine;
}
public double getMoreFine() {
return moreFine;
}
public ParkedCar getVehicle() {
return vehicle;
}
public PoliceOfficer getCopster() {
return copster;
}
public int getMinutes() {
return minutes;
}
public double getFine() {
return fine;
}
public String toString() {
String string = "Fine : " + this.fine
+ " Minutes: " + minutes
+ " " + vehicle.toString()
+ " " + this.getCopster().toString();
return string;
}
}
public class ParkedCar {
private String make;
private String model;
private String color;
private String license;
private static int minutes;
public ParkedCar() {
}
public ParkedCar(String carMake, String carModel, String carColor, String carLicense, int carMinutes) {
make = carMake;
model = carModel;
color = carColor;
license = carLicense;
minutes = carMinutes;
}
public String getMake() {
return make;
}
public String getModel() {
return model;
}
public String getColor() {
return color;
}
public String getLicense() {
return license;
}
public static int getMinutes() {
return minutes;
}
public String toString() {
String string = "Make: " + make
+ " Model: " + model
+ " Color: " + color
+ " License Plate: " + license;
return string;
}
}
public class ParkingMeter {
private static int minPurchased;
public ParkingMeter() {
}
public ParkingMeter(int carMinPurchased) {
minPurchased = carMinPurchased;
}
public static int getMinPurchased() {
return minPurchased;
}
public String toString() {
String string = "Minutes Purchased: " + minPurchased;
return string;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.