Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For health reasons, we need to control the number of persons that can be simultaneously in a room. We distinguish persons who are vaccinated and
For health reasons, we need to control the number of persons that can be simultaneously in a room. We distinguish persons who are vaccinated and those who are not.
Question II [50 points] java
- 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).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started