Results 1 to 1 of 1
  1. #1
    Anthony5347 is offline Member
    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0

    Default Parking Ticket Simulator

    Hello, I am doing the infamous Parking Ticket Simulator for my Java class at college. I have already completed the program and it producing the correct output. The only issue however, is that I am NOT using the PoliceOfficer class to issue the ticket. In other words, he is not checking to see if a ticket should be issued. Instead I have managed to make the ParkingTicket class do it. But the instructions require me to have the PoliceOfficer issue the ticket, NOT to have the ParkingTicket do it; which is how I got it to work. Im having trouble figuring out how to make the PoliceOfficer issue the ticket. Much appreciated as to who can help me with this. Here are the codes. The real issues are with the ParkingTicket class and the PoliceOfficer Class. The last code provided is the Demo. Also here are the instructions:

    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.


    Java Code:
    public class ParkedCar
    {
       private String make;
       private String model;
       private String color;
       private String licenseNumber;
       public int minutes;
       
       //Constructor with no arguments
       public ParkedCar()
       {
          make = "";
          model = "";
          color = "";
          licenseNumber = "";
          minutes = 0;
       }
       
       //constructor with arguments
       public ParkedCar(String cMake, String cModel,
                        String cColor, String cLicenseNum, int cMinutes)
       {
          make = cMake;
          model = cModel;
          color = cColor;
          licenseNumber = cLicenseNum;
          minutes = cMinutes;
       }
       
       //The set method sets a value for each field 
       public void set(String carMake, String carModel,
                       String carColor, String carLicenseNum,
                       int carMinutes)
       {
          make = carMake;
          model = carModel;
          color = carColor;
          licenseNumber = carLicenseNum;
          minutes = carMinutes;
       }
       
       //copy constructor initializes
       //the object as a copy of another
       //instructor object. 
       public ParkedCar(ParkedCar object2)
       {
          make = object2.make;
          model = object2.model;
          color = object2.color;
          licenseNumber = object2.licenseNumber;
          minutes = object2.minutes;
       }
    
       public String getMake()
       {
          return make;
       }
    
       public String getModel()
       {
          return model;
       }
       
       public String getColor()
       {
          return color;
       }
             
       public String getLicenseNumber()
       {
          return licenseNumber;
       }
       
       public int getMinutes()
       {
          return minutes; 
       }
      
       //converts everything into a string  
       public String toString()
       {
          String str = "\nMake: " + make +
                       "\nModel: " + model + 
                       "\nColor: " + color +
                       "\nLicense number: " + licenseNumber +
                       "\nMinutes parked: " + minutes;
          return str;
       }
       
       //comparing
       public boolean equals(ParkedCar ParkedCar2)
       {
          boolean status;
          
          if(make.equals(ParkedCar2.make) &&
             model.equals(ParkedCar2.model) &&
             color.equals(ParkedCar2.color) &&
             licenseNumber.equals(ParkedCar2.licenseNumber))
             
             status = true;
          else
             status = false;
             
          return status;      
       }
    }
    Java Code:
    public class ParkingMeter
    {
       public int minutesPurchased;
       
       //with no arguments 
       public ParkingMeter()
       {
          minutesPurchased = 0; 
       }
       
       //constructor with arguments
       public ParkingMeter(int purchase)
       {
          minutesPurchased = purchase;
       }
       
       //set method
       public void set(int purchase)
       {
          minutesPurchased = purchase;
       }
       
       //return method
       public int getMinutesPurchased()
       {
          return minutesPurchased; 
       }
       
       public ParkingMeter(ParkingMeter object2)
       {
          minutesPurchased = object2.minutesPurchased;  
       }
     
       public String toString()
       {
          String str = "\nMinutes purchased: " + minutesPurchased;
             
          return str;   
       }  
       
       public boolean equals(ParkingMeter ParkingMeter2)
       {
          boolean status;
          
          if(minutesPurchased == ParkingMeter2.minutesPurchased)
             status = true;
          else
             status = false;
             
          return status;      
       }
    }

    Java Code:
    public class ParkingTicket
    {
       private ParkedCar car;
       private PoliceOfficer officer;
       private ParkingMeter meter;
       double baseFine = 25.0;
       double hourlyFine = 10.0;
      
      
     
      
       public ParkingTicket()
       {  
          car = new ParkedCar();
         officer = new PoliceOfficer();
          meter = new ParkingMeter();
       } 
      
       public ParkingTicket(ParkedCar c, PoliceOfficer o,
                            ParkingMeter m)
       {
          car = new ParkedCar(c);
          officer = new PoliceOfficer(o);
          meter = new ParkingMeter(m);  
       }  
       
       public ParkingTicket(ParkingTicket object2)
       {
          car = object2.car;
          officer = object2.officer;
          meter = object2.meter;
       
       }                   
       
       public ParkedCar getParkedCar()
       {
          return new ParkedCar(car);
       }
       
       public PoliceOfficer getPoliceOfficer()
       {
          return new PoliceOfficer(officer);
       }
       
       public ParkingMeter getParkingMeter()
       {
          return new ParkingMeter(meter);
       }
    
       public double getFine()
       {
          double ticket;
          
          if (car.minutes <= meter.minutesPurchased)
          {
             ticket = 0;
          }
          else
             ticket = baseFine + (hourlyFine * ((car.minutes - meter.minutesPurchased) / 60)); 
             
          return ticket;    
       
       }
     
       public String toString()
       {
          String str = "\nVehicle information:\n" +
                      car +
                      "\n\nOfficer information:\n" +
                      officer + 
                      "\nFine: $" + getFine();
          return str;
       }
       
       public boolean equals(ParkingTicket ParkingTicket2)
       {
          boolean status;
          
          if(car.equals(ParkingTicket2.car) &&
             officer.equals(ParkingTicket2.officer) &&
             meter.equals(ParkingTicket2.meter) &&
             getFine() == ParkingTicket2.getFine())
             
             status = true;
          else
             status = false;
             
          return status;      
       }
    }
    Java Code:
    public class PoliceOfficer
    {
       private String name;
       private int badgeNumber;
      
       private ParkedCar car;
       private ParkingMeter meter;
       public ParkingTicket ticket;
       
       
       public PoliceOfficer()
       {
          name = "";
          badgeNumber = 0;
          car = new ParkedCar();
          meter = new ParkingMeter();
          ticket = new ParkingTicket();
       }
    
       public PoliceOfficer(String officerName, int officerBadge)
       
       {
          name = officerName;
          badgeNumber = officerBadge;
       }
       
       public void set(String officerName, int officerBadge)
       {
          name = officerName;
          badgeNumber = officerBadge;
       }
       
       public PoliceOfficer(PoliceOfficer object2)
       {
          name = object2.name;
          badgeNumber = object2.badgeNumber;
       }
       
       public String getOfficerName()
       {
          return name; 
       }
       
       public int getOfficerBadgeNumber()
       {
          return badgeNumber; 
       }
     
     
        public ParkedCar getParkedCar()
       {
          return new ParkedCar(car);
       }
       
       public ParkingMeter getParkingMeter()
       {
          return new ParkingMeter(meter);
       }
       
       public ParkingTicket getParkingTicket()
       {
          return new ParkingTicket(ticket);
       }
    
       public ParkingTicket ticket(ParkedCar car, ParkingMeter meter)
       {
          
          if(car.minutes > meter.minutesPurchased)
             return new ParkingTicket(ticket);
          else
             return null;
       }
       
       public String toString()
       {
          String str = "\nOfficer name: " + name +
                       "\nBadge number: " + badgeNumber;
          return str;
       }
       
       public boolean equals(PoliceOfficer PoliceOfficer2)
       {
          boolean status;
          
          if(name.equals(PoliceOfficer2.name) &&
             badgeNumber == PoliceOfficer2.badgeNumber &&
             ticket.equals(PoliceOfficer2.ticket))
             status = true;
          else
             status = false;
             
          return status;      
       }
    }
    Java Code:
    public class ParkingTicketDemo
    {
       public static void main(String[] args)
       {
          ParkedCar myCar = new ParkedCar("Ford", "Mustang","Red", "LMJCD",40);
          ParkingMeter myMeter = new ParkingMeter(60);
          PoliceOfficer myOfficer = new PoliceOfficer("Dane", 5565);
          ParkingTicket myTicket = new ParkingTicket(myCar,myOfficer, myMeter);
          
          System.out.println(myMeter);
          System.out.println(myTicket);
       }
    }
    Last edited by Anthony5347; 12-07-2013 at 06:15 AM.

Similar Threads

  1. Need Help with my ticket Program
    By Gruff in forum New To Java
    Replies: 4
    Last Post: 05-02-2013, 05:59 AM
  2. SCJP ticket for Sale
    By nphariharan in forum Java Certification
    Replies: 6
    Last Post: 07-14-2009, 11:38 AM
  3. Require SCJP 1.6 exam ticket
    By nphariharan in forum Java Certification
    Replies: 0
    Last Post: 07-12-2009, 07:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •