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
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