java多线程
假设车库有3个车位(用boolean[]数组来表示车库)可以停车,写一个程序模拟多个用户开车离开、停车入库的效果。注意:车位有车时不能停车。
首先是车库类
//车库
public class Parking {
private boolean[] place;//车位
private final int sum;//车位数量
public Parking(boolean[] place){
this.place = place;
this.sum = place.length;
}
public boolean getPlace(int i) {
return place[i];
}
public void setPlace(int i,boolean bool){
place[i] = bool;
}
public boolean isfull(){
for(boolean p : place){
if(!p){
//如果有空位
return false;
}
}
return true;
}
public int getSum() {
return sum;
}
}
车类
//车
public