Program : mp85 Points : 25 Due Date : May 10, 2006 Grace Date : May 12, 2006 (in class) (hand in hard copy of java files and script file - see below on how to generate it.) Description: Write a monitor for the unisex bathroom problem. Your program is to simulate the use of a Co-Ed resident hall bathroom. Some men and women have been complaining about the use of the bathroom. There is only one bathroom in the hall. As many women can use the bathroom as they want at the same time as long as there are NO men waiting or no men in the bathroom. The same is true for the men, that is, as many men can use the bathroom as they want at the same time as long as there are NO women waiting or no women in the bathroom. We want the program to prevent starvation and be fair. Note that there are 2 files: Bathroom.java and driver.java Bathroom.java defines one class named Bathroom with 4 public synchronized methods, named: women_enter_bathroom women_leave_bathroom men_enter_bathroom men_leave_bathroom. The driver.java has 3 classes: Woman, Man, and driver. Sample output is provided as well in the file - mp85.out. The behaviors of the men and women are specified in REQUIREMENTS 3 AND 4, respectively. The behavior of the driver program is in REQUIREMENT 5. The monitor, bathroom.java, has requirements specified in # 6 . The driver, driver.java, should have 3 classes, the Woman, the Man, and a driver. Store the files bathroom.java and driver.java in your java directory. You will need SmallScheduler.java and GetOpt.java from the previous program. REQUIREMENTS: 0. THE CLASSES MUST BE NAMED: Woman Man AND driver NO METHODS IN THESE 3 CLASSES ARE synchronized. (-10 if so.) 1. DO NOT USE ARRAYS OR SEMAPHORES. THE COMMAND LINE IS AS FOLLOWS assuming driver class has main: java driver -W numWomen -M numMen -l womenbath -r menbath -L womenwander -R menwander -T runTime these parameters have default values of 5 total women, 5 total men, 8 women maximum bath time, 8 men maximum bath time, 4 for women maximum wander time (random # up to 4 seconds), 4 for men maxmimum wander time (random # up to 4 seconds), and 20 seconds of run time. 2. Each woman and man should write out the age when they are doing something. (see sample output) 3. Man sequence: [Man(String name, int id, int menbath, int menwander Bathroom bathroom)] while true -> writes age and name of man and how long man is studying study for that long write age and name and that he has to use the bathroom enter the bathroom (at least try to) write age and name and that he is IN the BATHROOM. use the bathroom leave the bathroom write age and name and fact that he is finished with the bathroom end while 3. Woman sequence: [Woman(String name, int id, int womenbath, int womenwander Bathroom bathroom)] while true -> writes age and name of Woman and how long woman is studying study for that long write age and name and that she has to use the bathroom enter the bathroom (at least try to) write age and name and that she is IN the BATHROOM. use the bathroom leave the bathroom write age and name and fact that she is finished with the bathroom end while 5. driver sequence: gets the arguments using GetOpt (see RW solution.) Provide a usage line when one gives the command: java driver -U It should say: Usage: -W numWomen -M numMen -l womenbath -r menbath -L womenwander -R menwander -T runTime Echo all values of the parameters. Create a bathroom. Create the proper number of women and men. Write that all threads are started; run for the appropriate amount of time; write message to stop threads, and finally call System.exit(0). 6. Bathroom: Bathroom.java This Bathroom has 2 boolean variables: ok_for_women_inbathroom and ok_for_men_inbathroom Variables are needed to keep track of present number of Men and Women in the bathroom as well as variable for men and women waiting for the bathroom. I will describe the methods women_enter_bathroom and women_leave_bathroom. The corresponding methods for men are similar. women_enter_bathroom: if no men are waiting and no men are in the bathroom then increment the number of women in the bathroom by 1 and write appropriate message (with age and name) that she has begun using the bathroom. Otherwise increment the number of waiting women by 1, write out appropriate message that she is waiting, and WAIT. Note that when she no longer has to wait she should then increment number of women in the bathroom and write messsage that she is beginning to use the bathroom. women_leave_bathroom: Decrement number of women in bathroom, write appropriate message that she is finished using the bathroom. If she is the last woman in the bathroom and there are men waiting, write the cascading message (see sample output) set boolean variable appropriately, and send in the men. 7. Document your entire program (both files) according to javadoc descriptions for cs2430 class. 8. ASK QUESTIONS IN CLASS. SEE SAMPLE OUTPUT: mp85.out ON web page. Try to match this as much as possible. 9. Turn in a hardcopy of your java files and the script file, mp85.txt generated via the following commands. script mp85.txt javac *.java java driver -U java driver java driver -W6 -M4 -l9 -r7 -L3 -R5 -T30 exit