View the step-by-step solution to:



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:

  1. PCB Class
  2. 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.
  3. MaleThread and FemaleThread Classes
  4. 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.
  5. Main Test Program
  6. This program controls the simulation. It must have a PCB object to be used by the male and female threads.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.


Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question