package veterinarian; public class WaitingRoom { private int dogs = 0; private int cats = 0; public synchronized void EnterRoom(String animal, int id) throws InterruptedException { while(!checkConditions(animal)) { wait(); } if(animal.equals("cat")) { cats += 1; } if(animal.equals("dog")) { dogs += 1; } System.out.println(animal + " " + id + " entered! Dogs: " + dogs + ", Cats: " + cats); } public synchronized void ExitRoom(String animal, int id) { if(animal.equals("cat")) { cats -= 1; } if(animal.equals("dog")) { dogs -= 1; } System.out.println(animal + " " + id + " exited! Dogs: " + dogs + ", Cats: " + cats); notifyAll(); } private boolean checkConditions(String animal) { if(animal.equals("cat")) { return dogs <= 0 && cats <= 0; } else { if(cats > 0) { return false; } else { return dogs < 3; } } } }