31 lines
530 B
Java
31 lines
530 B
Java
package semaphore;
|
|
|
|
import java.util.Random;
|
|
|
|
public class Car {
|
|
|
|
// Simulated max time taken by a valet to park a car
|
|
private static final int MAX_PARKING_TIME = 3000;
|
|
|
|
private final int plate;
|
|
private static final Random generator = new Random();
|
|
|
|
public Car(int plate) {
|
|
this.plate = plate;
|
|
}
|
|
|
|
public int getPlate() {
|
|
return plate;
|
|
}
|
|
|
|
public void park() throws Exception {
|
|
int time = generator.nextInt(MAX_PARKING_TIME);
|
|
Thread.sleep(time);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "" + plate;
|
|
}
|
|
}
|