Question: JAVA Question II [50 points] In this question you have to change the driver class, the Vaccinated class and NotVaccinated class created in the first
![JAVA Question II [50 points] In this question you have to](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f92073c2485_80366f92073688b3.jpg)
JAVA Question II [50 points] In this question you have to change the driver class, the Vaccinated class and NotVaccinated class created in the first Question to meet the following conditions: A vaccinated cannot enter the room if there is a not vaccinated inside. At maximum 4 vaccinated can be simultaneously in the room. A not vaccinated can enter in the room only if the room is empty At maximum 1 not vaccinated can be in the room (must be alone in the room) Create necessary Semaphores in the driver class, pass this Semaphores to Vaccinated and NotVaccinated via the constructor. Use this semaphores to maintain the above conditions. Following is a possible Sample Run
additional information i need to create:
- Write a class SharedRoom. It has :
- 2 shared counters (countVacc and countNotVacc) initialized to 0. (use static)
- A static method print that prints the values of the two counters
- Write a Thread class Vaccinated. The main work of Vaccinated (the run method) is:
- Enter in the SharedRoom (increment the number of vaccinated in the room)
- Print the count of vaccinated and not vaccinated in the room
- Stay in the room for 5 seconds (sleep for 5 seconds)
- Leave the SharedRoom (decrement the number of vaccinated in the room)
- Write a Thread class NotVaccinated. The main work of NotVaccinated is:
- Enter in the SharedRoom (increment the number of not vaccinated in the room)
- Print the count of vaccinated and not vaccinated in the room
- Stay in the room for 5 seconds (sleep for 5 seconds)
- Leave the SharedRoom (decrement the number of not vaccinated in the room)
- Write a Drive class as following:
- Create 6 Vaccinated objects and 6 NotVaccinated objects and let them starts (you can use loop).
Vaccinated : 0 Not Vaccinated : 1 Vaccinated : 2 Not Vaccinated : 0 2 Vaccinated : 4 Not Vaccinated : 0 Vaccinated : 3 Not Vaccinated : 0 Vaccinated : 3 Not Vaccinated : : 0 Vaccinated : 4 Not Vaccinated : 4 0 Vaccinated : 4 Not Vaccinated : 0 Vaccinated : 0 Not Vaccinated : 1 Vaccinated : 0 Not Vaccinated : Vaccinated : O Not Vaccinated : 1 0 Vaccinated : 0 Not Vaccinated : 1 Vaccinated : 0 Not Vaccinated : 1 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
