Hello. I am fairly new to programming, and this new assignment has pushed me to my limits. I am almost done with it, I think, but I am doing something incorrect because I can't seem to get rid of all of my errors at the same time. Any help is appreciated. Thank you very much:
Design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes to design are:
- 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.
- ParkingMeter Class: simulates a parking meter.
- This classes only responsibility is to know the number of minutes of parking time that has been purchased.
-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.
-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.
Write a program to test the classes as well.
Here is what I have for my classes:
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 + "\nModel: " + model + "\nColor: " + color + "\nLicense 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; } }
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 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; } }
public class CarTest { 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!"); } } }
In this code, the only problem is "return ticket;" in the PoliceOfficer class. However, even if I got rid of that, I still don't know if my code would work... . Any help is appreciated. Thank you so much in advanced.
-TitanVex