Question

Project: Parking Ticket Simulator Problem Description: For this assignment you will design a set of classes that work...

Project: Parking Ticket Simulator
Problem Description:
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should design are:

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/**
 * This class should simulate a parked car, see exercise for description of
 * responsibilities
 * 
 */
class ParkedCar {

    private String make;
    private String model;
    private String color;
    private String licenseNumber;
    private int minutesParked;

    //omitted getter/setters

}
class ParkingMeter {

    private int minutesPurchased; 

    //omitted getter/setters
}
class PoliceOfficer {

    private String name;
    private String badgeNumber;

    public ParkingTicket patrol(ParkedCar car, ParkingMeter meter) {

        ParkingTicket ticket = null;

        // Calculate the total number of minutes parked over minutes
        // purchased
        int illegalMinutes = car.getMinutesParked()
                - meter.getMinutesPurchased();

        // if illegalMinutes, give ticket
        if (illegalMinutes > 0) {
            // Yes, it is illegally parked.
            ticket = new ParkingTicket(car, this, illegalMinutes);
        }

        return ticket;
    }

    //omitted getter/setters
}
class ParkingTicket {

    private ParkedCar car;
    private PoliceOfficer officer;
    private double fine;
    private int minutes;

    public final double BASE_FINE = 25.0;
    public final double HOURLY_FINE = 10.0;

    public ParkingTicket(ParkedCar car, PoliceOfficer officer, int minutes) {
        super();
        this.car = car;
        this.officer = officer;
        this.minutes = minutes;

        calculateFine();
    }

    private void calculateFine() {

        double hours = minutes / 60.0;
        int hoursAsInt = (int) hours;

        if ((hours - hoursAsInt) > 0) {
            hoursAsInt++;
        }

        // Assign the base fine.
        fine = BASE_FINE;

        // Add the additional hourly fines.
        fine += (hoursAsInt * HOURLY_FINE);
    }

    //omitted getter/setters
}
public static void main(String[] args) {

    // A green car was parked for 125 minutes
    ParkingTicketSimulator parkingTicketSimulator = new ParkingTicketSimulator();
    ParkedCar car = parkingTicketSimulator.new ParkedCar("Toyota", "2005",
            "Green", "ABC123", 125);

    // 60 minutes of time was purchased
    ParkingMeter meter = parkingTicketSimulator.new ParkingMeter(60);

    // Officer Jack was on duty
    PoliceOfficer officer = parkingTicketSimulator.new PoliceOfficer(
            "Sargent Jack Johnson", "8909");

    ParkingTicket ticket = officer.patrol(car, meter);

    // Did the officer issue a ticket?
    if (ticket != null) {
        System.out.println(ticket);
    } else {
        System.out.println("No crimes committed!");
    }
}
Add a comment
Know the answer?
Add Answer to:
Project: Parking Ticket Simulator Problem Description: For this assignment you will design a set of classes that work...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment =====================...

    Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment ===================== For this assignment you will create a set of classes from scratch (no provided class files for this assignment) that work together to simulate a police officer issuing a parking ticket. You should design the following classes / functionality within them: ===================== ParkedCar.java: ===================== This class should simulate a parked car. The class's responsibilities are as follows: - To store the car's make, model,...

  • Parking Ticket Simulator C++ HELP PLEASE

    For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should designare:• The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are:o To know the car’s make, model, color, license number, and the number of minutes that the car has been parked• The ParkingMeter Class: This class should simulate a parking meter. The class’s only responsibility is:o To know the number...

  • using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checkin...

    using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checking a parked car issuing a parking ticket if there is a parking violation. Here are the classes that need to collaborate: • The ParkedCar class: This class should simulate a parked car. The car has a make, model, color, license number. •The ParkingMeter class: This class should simulate a parking meter. The class has three parameters: − A 5-digit...

  • I need help with this java project and please follow the instruction below. thank Class Project...

    I need help with this java project and please follow the instruction below. thank Class Project - Parking Ticket simulator Design a set of classes that work together to simulate a police officer issuing a parking ticket. Design the following classes: •           The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. •          ...

  • Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need...

    Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example in the PPT) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked beyond their time...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • C# Car Instrument Simulation (Updated Question) Car Instrument Simulator Design a set of classes that work...

    C# Car Instrument Simulation (Updated Question) Car Instrument Simulator Design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are the following: • The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are as follows: o To know the car’s current amount of fuel, in liters. o To report the car’s current amount of fuel, in liters. o To be able to increment the amount of...

  • The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you w...

    The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you will design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are: • The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are – To know the car’s current amount of fuel, in gallons. – To report the car’s current amount of fuel, in gallons. – To...

  • Car Instrument Simulator

    Car Instrument SimulatorFor this assignment, you will design a set of classes that work together to simulate a car’s fuel gauge andodometer. The classes you will design are the following: The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are as follows:o To know the car's current amount of fuel, in gallons.o To report the car s current amount of fuel, in gallons.o To be able to increment the amount of fuel by I gallon. This simulates...

  • Design a set of classes that work together to simulate the Stock Transaction System. You should...

    Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows:    -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on a stock market. The class's...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT