Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Due to Covid-19, restaurants (if allowed to open) suffer restrictions in their capacities. This assignment realizes a simulation of a restaurant with waiting guests. Sub-task

image text in transcribed

Due to Covid-19, restaurants (if allowed to open) suffer restrictions in their capacities. This assignment realizes a simulation of a restaurant with waiting guests. Sub-task 1 (2 points) call assign() blocks until at least one Runnable is available inside the queue. Subsequently, a Runnable is extracted and returned. implementation, you may, e.g., use a LinkedList. Sub-task 2 (5 points) Now implement the class Table extends Thread which provides the following constructors and methods: - public Table(GuestwaitingQueue gw). The constructor receives a Guestewaitingqueue as a parameter. - public void run(). another guest. - public synchronized void dostop(). This method takes care that the Restaurant stops waiting, does no longer start fresh dinings but terminates as soon the current guest (if any) has finished. Sub-task 3 (3 points) Implement the class Restaurant. This class receives in its constructor the maximal number of tables, i.e., threads to be created. A Restaurant offers for following constructors and methods: - public Restaurant(int threadCount). constructor receiving the number of threads. It should initialize all attributes. It should establish the required number of tables and start the corresponding threads. - public synchronized void reserve(Runnable task) throws Exception should add Runnable into the queue. If service has already been stopped, an IllegalstateException should be thrown. - public synchronized void stop() terminates waiting as well as execution of all threads and prohibits that further Runnables are added to the queue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions