Sie sind auf Seite 1von 2

The purpose of this project is to write a program in Java for simulating the operation of a gas station.

A gas station has several gas pumps and each pump may have a queue of cars waiting for service. Your program should ask the user for the length of the simulation period in minutes. During the simulation time period cars will arrive at the gas station at random time intervals. The time elapsed between two consecutive arrivals is generated as a random number between 0 and 6 minutes. Upon arrival each car will be given a serial number that keeps track of the order in which they arrived. Every time a car arrives, it will join the shortest queue. The gas station must have 4 pumps where cars will wait in line for service while the pump is busy. This means that each pump will have its own queue whose length will be used by the new arrivals in order to choose the shortest queue. Once in a queue the cars must stay there until they are served. The main loop of the simulation program is controlled by a counter representing the clock. The clock keeps advancing by one minute at a time and when the time is up for the next arrival a new Car object is created. This car will go immediately to the pump with the shortest queue. If the queue is empty then, of course, it will be the only member of that queue. At the same time a new random number is generated for predicting the time of the next arrival. The advancement of the clock will trigger other events. Namely, if a car has just finished filling up at that time it will leave the gas station and thus, the pump becomes free. Then, at each pump that is free the car next in line (if any) begins pumping. The service time will be obtained as a random number between 1 and 25 minutes. (One needs at least 1 minute overhead for operating the pump.) This number is determined for each car separately at the time when it starts filling up. The time needed for filling up the car will be used for computing the time when the pump next will become free. This time is saved as part of the current state of the pump and will be used for checking the availability of the pump later on. Your program should define a Car class to create car objects and a Pump class to create pump objects. Also a Queue class is to be defined to create a queue object for each pump. Your program should trace the events that occur during the simulation period and keep track of some important cumulative measures. At the end of the simulation the program should print these data: 1) The arrival and the departure time of each car whose service was completed by the end of the simulation period. 2) The longest transit time for such cars (the time between arrival and departure). 3) The shortest transit time for such cars.

4) The longest waiting time for such cars. 5) The maximum length of each queue in the course of simulation.

Das könnte Ihnen auch gefallen