Question: In this exercise you must implement in Java another classic control problem. competition - the problem of monkeys crossing the river. Problem description: Suppose there

In this exercise you must implement in Java another classic control problem. competition - the problem of monkeys crossing the river.

Problem description: Suppose there are monkeys on both banks of the river, and from time to time the monkeys decide to go to the other side looking for food. the passage to the other river bank is made through a rope bridge. More than one monkey can cross the bridge at the same time, but this is only possible if they are going in the same direction.

Implementation: Implement a program that controls the passage of monkeys across the bridge using concurrency control mechanism with semaphores, in the Java language. To test the system, create 10 threads that represent the monkeys, initially placing half of them on each bank of the river. Whenever a monkey starts or completes the crossing, print a message on the screen identifying the monkey. After testing the above program, now create a new version of the program by adding two gorillas, one on each side of the river. As gorillas are very heavy, they can only cross the bridge alone. As other monkeys are afraid of gorillas, they will be priority to make the crossing.

include main class for test.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!