Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java; I need to create a solution to the philosopher's Dining Problem using an arbitrator. The arbitrator is supposed to give permission before the

Using Java;

I need to create a solution to the philosopher's Dining Problem using an arbitrator. The arbitrator is supposed to give permission before the philosophers are able to eat and each philosopher needs to have 2 forks to eat. If they are not eating they are thinking. The output of the program need to look like :

image text in transcribed

I have some code written but I keep getting errors that I'm not sure how to fix. The main error I get an error on the for loop in the main class that says "error: illegal start of type". Any help that can be provided would be helpful. Along with anything else that looks like it needs fixing. Thanks.

Code:

import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays;

public class DiningProblem { public static void main(String[] args) { class Fork { private int id; private boolean availableFlag = true; private static final String pickUpMsg = " is not available"; private static final String putDownMsg = " is not being held"; public Fork(int id) { this.id = id; } public boolean isAvailable() { return availableFlag; } public void pickUp() { if (!availableFlag) { throw new IllegalStateException(toString() + pickUpMsg); } availableFlag = false; } public void putDown() { if (availableFlag) { throw new IllegalStateException(toString() + putDownMsg); } availableFlag = true; } } class Main { public Main() { Fork[] forks = new Fork[5]; for (int i = 0; i Philosopher: Alpha Thoughts: 36, Meals: 11 Critical section time (ns): 73334 Total time (ns): 10938677 Time Ratio -- Critical section / Total: 0.0067 Philosopher: Bravo Thoughts: 28, Meals: 3 Critical section time (ns): 40115 Total time (ns): 11119427 Time Ratio -- Critical section / Total: 0.0036 Philosopher: Charlie Thoughts: 29, Meals: 9 Critical section time (ns): 45989 Total time (ns): 11183193 Time Ratio -- Critical section / Total: 0.0041 Philosopher: Delta Thoughts: 33, Meals: 11 Critical section time (ns): 53637 Total time (ns): 10909225 Time Ratio -- Critical section / Total: 0.0049 Philosopher: Echo Thoughts: 28, Meals: 14 Critical section time (ns): 34222 Total time (ns): 10809084 Time Ratio -- Critical section / Total: 0.0032 Philosopher: Alpha Thoughts: 36, Meals: 11 Critical section time (ns): 73334 Total time (ns): 10938677 Time Ratio -- Critical section / Total: 0.0067 Philosopher: Bravo Thoughts: 28, Meals: 3 Critical section time (ns): 40115 Total time (ns): 11119427 Time Ratio -- Critical section / Total: 0.0036 Philosopher: Charlie Thoughts: 29, Meals: 9 Critical section time (ns): 45989 Total time (ns): 11183193 Time Ratio -- Critical section / Total: 0.0041 Philosopher: Delta Thoughts: 33, Meals: 11 Critical section time (ns): 53637 Total time (ns): 10909225 Time Ratio -- Critical section / Total: 0.0049 Philosopher: Echo Thoughts: 28, Meals: 14 Critical section time (ns): 34222 Total time (ns): 10809084 Time Ratio -- Critical section / Total: 0.0032

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_2

Step: 3

blur-text-image_3

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

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

Has the priority order been provided by someone else?

Answered: 1 week ago

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

Are the rules readily available?

Answered: 1 week ago