PLEASE PROVIDE A JAVA PROGRAM:
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.
he 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 have a PCB object to be used by the male and female threads.
Recently Asked Questions
- I would like someone to review my prospectus and just add material to it. (In bold) The prospectus needs a 'gap' and on the topic of 'eye tracing.' If someone
- The operating budget for a certain company shows a net income of $ 284 comma 690. $284,690. To achieve this, the company is targeting sales of $ 606 comma
- If I record a debit to cash it will: a. Have no effect on the account balance b. Depend on the current balance as to if it increases/decreases c. Decrease the