Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions