You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
2 years ago
|
/*
|
||
|
* To change this license header, choose License Headers in Project Properties.
|
||
|
* To change this template file, choose Tools | Templates
|
||
|
* and open the template in the editor.
|
||
|
*/
|
||
|
package gazstation2;
|
||
|
|
||
|
import java.util.Random;
|
||
|
import java.util.logging.Level;
|
||
|
import java.util.logging.Logger;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @author denis
|
||
|
*/
|
||
|
class FilingColumn {
|
||
|
|
||
|
private int bigTank;
|
||
|
private volatile boolean isOpen;
|
||
|
|
||
|
public FilingColumn (){
|
||
|
bigTank = new Random().nextInt(500);
|
||
|
isOpen = true;
|
||
|
}
|
||
|
|
||
|
public int getBigTank() {
|
||
|
return bigTank;
|
||
|
}
|
||
|
|
||
|
public synchronized boolean getFuel(Car car, int fuel) {
|
||
|
if(isOpen){
|
||
|
if(bigTank<fuel){
|
||
|
System.out.println(car.name + ": не достаточно топлива. Ожидает.");
|
||
|
GazStation.getState().callGazProducer(this);
|
||
|
isOpen = false;
|
||
|
}else{
|
||
|
bigTank -= fuel;
|
||
|
car.tank += fuel;
|
||
|
System.out.println("--------------------------" + car.name + ": заправил " + fuel + " л. Объем топлива: " + car.tank);
|
||
|
}
|
||
|
}
|
||
|
return isOpen;
|
||
|
}
|
||
|
|
||
|
public void addFuel(int fuel){
|
||
|
bigTank += fuel;
|
||
|
isOpen = true;
|
||
|
}
|
||
|
}
|