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