Question

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 limit. If a car is found to be in violation, then the car is towed away (removed from the parking lot). Note may need other classes to have a true OOD. The simulation should have the following parameters:

A lot with 20 spaces

Cars can pay for parking in 15 minute increments: 15, 30, 45, and 60 minutes.

Cars can be parked at a max of 1 hour. Therefore a car could pay for 30 minutes of parking, and park for 45 minutes. Any car parked for more than an hour is automatically in violation and is towed away.

Cars can park for 5 - 70 minutes (using 5 minute increments)

Cars that are towed are just removed from the lot

The police officer should patrol at least once every 10 minutes on average.

If the lot is full, cars are removed from the simulation.

The program should only ask the user for the amount of time (in minutes) to run the simulation. The simulation should run to the end and output the following data:

Number of cars that were found in violation

Number of cars that parked

Number of cars that were turned away because the lot was full

The average # of full spaces

The program should be written in c++ using visual studio.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class ParkedCar 
{


//Define Variables

    private String CarMake;
    private String CarModel;
    private String CarColour;
    private String CarLicensePlate;
    private static int NumberOfMinutesParked;


//Define Constructors

    // NO ARGUMENT CONSTRUCTOR
    // Set Vaules to Zero or null

    public ParkedCar()
    {
        CarMake = " ";
        CarModel = " ";
        CarColour = " ";
        CarLicensePlate = " ";
        NumberOfMinutesParked = 0;  
    }



    // CONSTRUCTOR WHICH ACCEPTS AN INPUT

    public ParkedCar(String Make,String Model,String Colour,String Reg, int NoMinsPkd)
    {
        CarMake = Make;
        CarModel = Model;
        CarColour = Colour;
        CarLicensePlate = Reg;
        NumberOfMinutesParked = NoMinsPkd;
    }


    // Use the SET Method
    // Set the variables - no needed
    public void setMake(String Make)
    {
        CarMake = Make;
    }

    public void setModel(String Model)
    {
        CarModel = Model;
    }

    public void setColour(String Colour)
    {
        CarColour = Colour;
    }

    public void setReg(String Reg)
    {
        CarLicensePlate = Reg;
    }

    public void setNoMinsPkd(int NoMinsPkd)
    {
        NumberOfMinutesParked = NoMinsPkd;
    }

    // USE THE GET METHODS
    // Get the Variables - used to read in values
    public String getMake()
    {
        return CarMake;
    }
    public String getModel()
    {
        return CarModel;
    }
    public String getColour()
    {
        return CarColour;
    }
    public String getReg()
    {
        return CarLicensePlate;
    }
    public static int getNoMinsPkd()
    {
        return NumberOfMinutesParked;
    }

    // USE THE TO STRING METHODS
    // Output to a Sting 
    public String toString() 
        {

            String PkdCar = "Make: " + CarMake
                + "\nModel: " + CarModel
                + "\nColor: " + CarColour
                + "\nLicense Plate: " + CarLicensePlate;
            return PkdCar;
        }

}
public class GardaOfficer //extends ParkedCar 
{
    // Define all the variables
    //==========================
    private String Name;
    private String BadgeNumber;
    private double Ticket;



    // Constructor to accept all the variables
    //========================================

    public GardaOfficer(String n, String num)
    {
        Name = n;
        BadgeNumber = num;

    }

    // NO ARGUMENT CONSTRUCTOR
    //========================

        public GardaOfficer()
    {
        Name = "";
        BadgeNumber = "";


    }

    // SET METHODS
    //===============

    public void setName(String n)
    {
        Name = n;
    }


    public void setBadgeNumber(String num)
    {
        BadgeNumber = num;
    }




    // GET METHODS
    //===============

    public String getName()
    {
        return Name;
    }

    public String getBadgeNumber()
    {
        return BadgeNumber;
    }

    // TO STRING METHOD
    //=================

    public String toString() 
    {
        String GardaString = "Garda : " + this.Name
                        + "\nBadge: " + BadgeNumber
                        + "\nTicket: " + Ticket;
        return GardaString;

    }




    public ParkingTicket search(ParkedCar car, ParkingMeter meter) 
        {
            GardaOfficer Garda = new GardaOfficer(this.Name,this.BadgeNumber);
            int time = ParkedCar.getNoMinsPkd() - ParkingMeter.getPurchased();

            if(ParkedCar.getNoMinsPkd() > ParkingMeter.getPurchased()) 
                {
                if(time <= 60) 
                    {
                        Ticket = 50;

                    }

                else 
                    {
                        Ticket = 50 + (10 * (time/60));
                    }
                }

                if(time <0)

                        return null;
                        return new ParkingTicket(car, Garda, getTicket(), time);

                    }

                public double getTicket()
                    {
                        return Ticket;
                    }

                public void setTicket(double ticket) 
                    {
                        this.Ticket = Ticket;
                    }
} 
public class ParkingTicket
{

//Define Variables
private ParkedCar Vehicle;
private GardaOfficer GuardString;
private double ParkingFine;
private int Minutes;
private double firstFine = 50;
private double moreFine = 50;

public ParkingTicket()
    {
    }

// CONSTRUCTOR WHICH ACCEPTS AN INPUT
public ParkingTicket(ParkedCar car, GardaOfficer Guard, double guyFine, int mins) 
    {

        Vehicle = car;
        GuardString = Guard;
        ParkingFine = guyFine;
        Minutes = mins;
    }

    // Use the SET Method
    // Set the variables - not needed



    // USE THE GET METHODS
    // Get the Variables
    public void getTotalFine() 
        {
            int time = ParkedCar.getNoMinsPkd() - ParkingMeter.getPurchased();

            if (time <= 60) 
                {
                    ParkingFine = firstFine;
                } 
            else 
                {
                    ParkingFine = firstFine + moreFine * (time / 60);
                }
        }

    public double getFirstFine() 
        {
            return firstFine;
        }

    public double getMoreFine() 
        {
            return moreFine;
        }

    public ParkedCar getVehicle() 
        {
            return Vehicle;
        }

    public GardaOfficer getGuardString() 
        {
            return GuardString;
        }

    public int getMinutes() 
        {
            return Minutes;
        }

    public double getFine() 
        {
            return ParkingFine;
        }


    // USE THE TO STRING METHODS
    // Output to a Sting 
    public String toString() 
        {

            String TicketString = "Fine : " + this.ParkingFine
                            + "\nMinutes: " + Minutes
                            + "\n" + Vehicle.toString()
                            + "\n" + this.getGuardString().toString();

            return TicketString;

        }
}

Finally

//This is a demo file to show the program

public class DemoCar 
{

    public static void main(String[] args) 
        {

            ParkedCar Test1 = new ParkedCar("BMW", "2014", "Yellow", "141D12345", 30);
            ParkingMeter parking = new ParkingMeter(50);
            GardaOfficer Murphy = new GardaOfficer("Guard Murphy", "10");
            ParkingTicket ticket = Murphy.search(Test1, parking);

        if (ticket != null) 
            {
                System.out.println(ticket.toString());
            } 
        else 
            {
                System.out.println("No ticket issued!");
            }


// A second car checked to see if it passes or not, it's over
            ParkedCar Test2 = new ParkedCar("VW", "2001", "Green", "01D321", 225);
            ParkingMeter parking2 = new ParkingMeter(200);
            ParkingTicket ticket2 = Murphy.search(Test2, parking2);

        if (ticket != null) 
            {
                System.out.println(ticket.toString());
            } 
        else 
            {
                System.out.println("No ticket issued!");
            }
        }
}
Add a comment
Know the answer?
Add Answer to:
Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need...
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
  • 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...

  • 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...

  • 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,...

  • Overview For this assignment, we will practice using stacks and queues. In this exercise, you will...

    Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...

  • Overview For this assignment, we will practice using stacks and queues. In this exercise, you will...

    Overview For this assignment, we will practice using stacks and queues. In this exercise, you will create two stacks and a queue to keep track of cars using a parking lot. We will use the nature of the stacks and queues to solve the problem. Specifications Rules FIU has opened a new valet parking lot next to the PC building that requires a special decal to park. If the car does not have the correct parking decal, the driver should...

  • 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. •          ...

  • The Parking Garage Problem

    The Scratchemup parking garage contains a single lane that holds up to 10 cars. Cars arrive at the south end of the garage and leave from the north end. If a customerarrives to pick up a car that is not the northernmost, all cars to the north of his car are moved out, her car is driven out, and the other cars are restored in thesame order that they were in originally. Whenever a car leaves, all cars to the...

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if,...

    I need help in C++ . Project 3 – Parking Deck Ticketing System Objectives: Use if, switch, and loop statements to solve a problem. Use input and output statements to model a real world application Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then...

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
ADVERTISEMENT