Question
PLEASE help me with the following lab. Please write a Java code in Eclipse. Please follow the following instructions: Scenario/Summary A university wants to demonstrate
PLEASE help me with the following lab. Please write a Java code in Eclipse. Please follow the following instructions:
Scenario/Summary
A university wants to demonstrate its political correctness by applying the Supreme Court's "Separate but equal is inherently unequal" doctrine to gender as well as race. As such, it has decided that both genders will use the same bathroom facilities. In order to preserve some tradition, however, it decrees that when a woman is in the bathroom, only other women may enter, and when a man is in the bathroom, only other men may enter. Each politically correct bathroom will have a sign on the outside indicating what state the bathroom is in; Empty, Women Present, or Men Present.
Design and develop this multi-threaded application that will simulate the usage of the bathroom according to the rules laid out by university. A status report should be available whenever anyone enters or leaves the bathroom which should include the gender of the person entering or leaving, the state of the bathroom, the number of men and/or women waiting, and number of occupants inside, and the gender of the occupants currently in the bathroom.
Implementation
The following classes should be implemented:
PCB Class
This class really does all the work of synchronizing access to the PCB. The PCB has a state, which reflects whether it is empty, or whether there are males or females inside. It also must keep track of the number of occupants which are inside, and the number that are waiting to get inside. There can be males or females inside or waiting. The PCB must have a mean of blocking the thread which is trying to gain access if the state of the PCB does not permit access (i.e., when occupants are females, and males are trying to get access). There should be a maleEnters( ) method and a femaleEnters( ) method. These methods check the state to see whether the male or female thread is allowed to enter or must be blocked. Also, there should be a femaleExits( ) method and a maleExits( ) method. These methods update the counter and state member variables appropriately.
MaleThread and FemaleThread Classes
These classes contain the code that simulates the actions of a male or female thread entering and exiting the PCB. These two classes can either inherit from the Thread class or implement the Runnable interface. The constructor for these two classes should accept a PCB object so that all the male and female threads are using the same PCB object.
Main Test Program
This program controls the simulation. It must create a PCB object to be used by the male and female threads.
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