I was working on this problem earlier. I have solved it, except for one part. It says that I have to generate a parking ticket from my 'ParkingTicket' class. Right now, in my Demo class, I have just had the system output all of the different parts it needs to generate the ticket, although it doesn't generate the parking ticket, per se. Here is the code I use now to generate the output:
import java.text.DecimalFormat; public class CarTest { public static void main(String[] args) { DecimalFormat money = new DecimalFormat("$0.00"); ParkedCar vehicle = new ParkedCar("Honda", "Accord", "Black", "452-BTS", 130); ParkingMeter meter = new ParkingMeter(60); PoliceOfficer copster = new PoliceOfficer("John Doe", 1337); ParkingTicket ticket = PoliceOfficer.examine(vehicle, meter); if(ticket != null) { //System.out.println(ticket); System.out.println(vehicle.toString()); System.out.println(meter.toString()); System.out.println(copster.toString()); System.out.println("Fine Total: " + money.format((ticket.getFine()))); } else { System.out.println("Car is not doing anything wrong!"); } } }
What I want is in the 'if(ticket!= null) {' area. Rather than having all of those outputs, I would like to just generate the ParkingTicket in the ParkingTicket class. If you know how to do this, I would be really grateful.
-TitanVex