package carafe_énoncé_v1;

public class Carafe
 {
  private static int CONTENANCE_STANDARD = 100;
  private int quantite;
  private final int contenance;

  public Carafe(int contenance) {
    this.quantite = 0;
    this.contenance = contenance;
  }

  public Carafe() {
    this(CONTENANCE_STANDARD);
  }

  public void remplir() throws InterruptedException {
    synchronized (this) {
		quantite = contenance;
		this.notifyAll();
	}
  }

  public void retirer(int q) throws InterruptedException {
    synchronized (this) {
    	while(quantite == 0) {
			this.wait();
		}
		quantite -= q;
		if (quantite <= 0) {
			quantite =0;
		}
	}
  }

  public boolean estVide() {
    synchronized (this) {
		return quantite == 0;
	}
  }

  @Override
  public String toString() {
    return "la carafe contient " + quantite + "cl";
  }
}
