import java.util.*; // for ArrayList
public class ParkingTicketSimulator
{
public static void main( String [ ] args )
{
// Create some parking meters numbered 1 through NUM_PARKING_METERS.
int NUM_PARKING_METERS = 30;
ParkingMeter[] meters = new ParkingMeter[ NUM_PARKING_METERS + 1 ];
for( int i = 1; i < NUM_PARKING_METERS + 1; i++ )
{
meters[ i ] = new ParkingMeter( "Elm", "13", i );
meters[ i ].setParkedCar( null );
}
// Create some cars.
ArrayList<ParkedCar> cars = new ArrayList<ParkedCar>();
cars.add( new ParkedCar( "Ford", "Mustang", "RED", "STANG 11" ) );
cars.add( new ParkedCar( "Chevy", "Camaro", "BLACK", "CAM 11" ) );
cars.add( new ParkedCar( "Toyota", "Camry", "SILVER", "ABC 123" ) );
cars.add( new ParkedCar( "Nissan", "Stanza", "BLACK", "WAS1234" ) );
cars.add( new ParkedCar( "Pontiac", "G5", "WHITE", "XYZ 999" ) );
cars.add( new ParkedCar( "Honda", "Element", "GREEN", "GONE NOW" ) );
cars.add( new ParkedCar( "Kia", "Sedona", "YELLOW", "MNP 354" ) );
cars.add( new ParkedCar( "Audi", "S6", "SILVER", "MY AUDI" ) );
cars.add( new ParkedCar( "Acura", "ZDX", "RED", "BIGBUCKS" ) );
cars.add( new ParkedCar( "Lincoln", "MKZ", "BLACK", "LINC 10" ) );
cars.add( new ParkedCar( "Volvo", "S80", "GRAY", "XED 925" ) );
cars.add( new ParkedCar( "Hyundai", "Accent", "RED", "JDR 328" ) );
cars.add( new ParkedCar( "Honda", "Civic", "RED", "KST 957" ) );
cars.add( new ParkedCar( "BMW", "7", "RED", "BMW 7" ) );
cars.add( new ParkedCar( "Lexus", "CT", "BLUE", "DHE 351" ) );
cars.add( new ParkedCar( "Kia", "Optima", "WHITE", "LEF 291" ) );
cars.add( new ParkedCar( "Yugo", "55", "RUST", "YUGOIGO" ) );
// Park the cars and pay the meters.
meters[ 2 ].setParkedCar( cars.get( 4 ) );
meters[ 2 ].setMinutesRemaining( 120 );
meters[ 5 ].setParkedCar( cars.get( 15 ) );
meters[ 5 ].setMinutesRemaining( 45 );
meters[ 6 ].setParkedCar( cars.get( 6 ) );
meters[ 6 ].setMinutesRemaining( 60 );
meters[ 8 ].setParkedCar( cars.get( 7 ) );
meters[ 8 ].setMinutesRemaining( 90 );
meters[ 10 ].setParkedCar( cars.get( 5 ) );
meters[ 10 ].setMinutesRemaining( 120 );
meters[ 13 ].setParkedCar( cars.get( 16 ) ); // The Yugo did not pay the meter!
meters[ 16 ].setParkedCar( cars.get( 9 ) );
meters[ 16 ].setMinutesRemaining( 30 );
meters[ 28 ].setParkedCar( cars.get( 10 ) );
meters[ 28 ].setMinutesRemaining( 120 );
meters[ 30 ].setParkedCar( cars.get( 11 ) );
meters[ 30 ].setMinutesRemaining( 120 );
// Create a police officer.
// Have cop check all the cars.
PoliceOfficer theCop = new PoliceOfficer( "Barney Fife", "12345" );
for( int i = 1; i < NUM_PARKING_METERS + 1; i++ )
{
// Check each car to see if ticket can be issued.
ParkingTicket aTicket = theCop.checkMeter( meters[i] );
if( aTicket != null )
{
System.out.println( aTicket );
}
// Chalk the tires of all cars.
if( meters[ i ].getParkedCar() != null )
{
meters[ i ].getParkedCar().setTireMarked();
}
}
// Advance the clock two hours.
for( int i = 1; i < NUM_PARKING_METERS + 1; i++ )
{
meters[ i ].setMinutesRemaining( 0 );
}
// Some cars leave, others arrive.
meters[ 2 ].setParkedCar( cars.get( 16 ) ); // The Yugo moves to another spot.
meters[ 2 ].setMinutesRemaining( 120 );
meters[ 5 ].setParkedCar( null );
meters[ 6 ].setParkedCar( null );
meters[ 8 ].setParkedCar( null );
meters[ 10 ].setParkedCar( cars.get( 1 ) );
meters[ 10 ].setMinutesRemaining( 20 );
meters[ 13 ].setParkedCar( null );
meters[ 14 ].setParkedCar( cars.get( 3 ) );
meters[ 14 ].setMinutesRemaining( 40 );
meters[ 15 ].setParkedCar( cars.get( 14 ) );
meters[ 15 ].setMinutesRemaining( 120 );
meters[ 17 ].setParkedCar( cars.get( 12 ) );
meters[ 17 ].setMinutesRemaining( 60 );
meters[ 21 ].setParkedCar( cars.get( 8 ) );
meters[ 21 ].setMinutesRemaining( 120 );
meters[ 29 ].setParkedCar( cars.get( 13 ) );
meters[ 30 ].setMinutesRemaining( 120 );
// One half hour passes before the cop checks meters.
for( int i = 1; i < NUM_PARKING_METERS + 1; i++ )
{
meters[ i ].setMinutesRemaining( meters[ i ].getMinutesRemaining() - 30 );
}
// Cop checks meters again.
for( int i = 1; i < NUM_PARKING_METERS + 1; i++ )
{
// Check each car to see if ticket can be issued.
ParkingTicket aTicket = theCop.checkMeter( meters[i] );
if( aTicket != null )
{
System.out.println( aTicket );
}
// Chalk the tires of all cars.
if( meters[ i ].getParkedCar() != null )
{
meters[ i ].getParkedCar().setTireMarked();
}
}
}
}