1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NARA [144]
4 years ago
13

Implement the Dining Philosophers problem (described on pages 167-170 in the textbook (chapter 2.5.1)). Create a Graphical User

Interface - showing which philosopher is eating, and which is waiting/thinking at any given time. Show the forks. Use Java programming language for this project.
Computers and Technology
1 answer:
zhuklara [117]4 years ago
3 0

Answer: Provided in the explanation section

Explanation:

class philosopher extends Thread

{

public void run()

{

diningps.count++;

philosopher(diningps.count);

}

public void philosopher(int i)

{

take_forks(i);

System.out.println(i+"philosopher Eating");

put_forks(i);

}

public void take_forks(int i)

{

while(diningps.mutex<=0)

{

System.out.println(i+"philosopher has to be wait while other philosopher in testing");

}

diningps.state[i]="HUNGRY";

test(i);

diningps.mutex=1;

while(diningps.S[i]<=0)

{

System.out.println(i+"philosopher has to be wait while his left or right side philosopher eating.");

}

}

public void put_forks(int i)

{

while(diningps.mutex<=0)

{

System.out.println(i+"philosopher has to be wait while other philosopher in testing");

}

diningps.state[i]="THINK";

test((i+4)%5);

test((i+1)%5);

diningps.mutex=1;

}

public void test(int i)

{

if(diningps.state[i]=="HUNGRY" && diningps.state[(i+4)%5]!="EAT" && diningps.state[(i+1)%5]!="EAT")

{

diningps.state[i]="EAT";

diningps.S[i]=1;

}

}

}

class diningps

{

static int mutex=1;

static int S[]={0,0,0,0,0};

static String state[]={"THINK","THINK","THINK","THINK","THINK"};

static int count=-1;

public static void main(String ar[])

{

philosopher ob=new philosopher();

philosopher ob1=new philosopher();

philosopher ob2=new philosopher();

philosopher ob3=new philosopher();

philosopher ob4=new philosopher();

ob.start();

ob1.start();

ob2.start();

ob3.start();

ob4.start();

}

}

cheers i hope this helped !!

You might be interested in
A company that connects through your communications line to its server, which connects you to the Internet, is a(n)
hammer [34]
Internet server provider
4 0
3 years ago
What is the impact of using computer in office?​
yawa3891 [41]

Answer:

It significantly enhance productivity.It can increase the speed and accuracy of many work processes, which improves overall worker efficiency. Documents can be written and edited much more quickly with the aid of a word processing program, and procedures, such as billing and accounting, can also occur more rapidly and with fewer errors.Computers in the office increase productivity not only in areas such as word processing, data management and information access, but also in information creation, collation and ultimately storage.

8 0
3 years ago
List three ways on how it's good to meet online and real life
nikitadnepr [17]

Answer:

Explanation:

How to meet people in real life

1. We can meet people if you go to your friend's party, is a great opportunity to meet friends from your friends.

2. We must go to events, in this case, if you like to read books, go to reading events.

3. We can use public transportation if you see someone reading your favorite book is the best opportunity.

How to meet people online

1. We can meet people in social media, but there are a lot of fake accounts, take care.

2. There are special platforms to meet people or to find love.

3. We could meet people on educational websites or apps, for example, if we want to learn Spanish, we can meet Spanish people.

3 0
3 years ago
Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter a value for one edge of a
morpeh [17]

Answer:

I'll answer this question with a Pseudocode

<em>1. Start</em>

<em>2. Input Length</em>

<em>3. Surface Area1 = Length * Length</em>

<em>4. Surface Area2 = 6 * Surface Area1</em>

<em>5. Volume = Length * Length * Length</em>

<em>6. Print Surface Area1</em>

<em>7. Print Surface Area2</em>

<em>8. Print Volume</em>

<em>9. Stop</em>

<em />

Explanation:

The first line starts the Pseudocode

The second line accepts input for Length of the cube

The third line calculates the surface area of 1 side

The fourth line calculates the surface area of the cube

The fifth line calculates the volume of the cube

The sixth to ninth line prints the calculated parameters

The Pseudocode ends on line 9

8 0
4 years ago
Tyler is using a word processor to complete his homework. As he is typing, the space bar gets stuck. How can Tyler properly clea
LUCKY_DIMON [66]
Fourth line would be the correct answer
6 0
3 years ago
Other questions:
  • Write a program having a concrete subclass that inherits three abstract methods from a superclass. Provide the following three i
    11·1 answer
  • Earning wise scope of web and mobile app development
    11·1 answer
  • What is difference between RAM and ROM?
    13·1 answer
  • . It is essential for a relay energized by alternating current to have A. many turns of small wire. B. a laminated core and a sh
    8·1 answer
  • Siona needs to make sure her ads are getting a minimum number of impressions on the top of the page. What type of automated bidd
    10·1 answer
  • Real GDP is found by removing the effects of inflation. How is this done mathematically?
    5·1 answer
  • Is the Internet dangerous?
    10·2 answers
  • Can any software run on any processor
    5·1 answer
  • What is an example of an intelligent automation solution that makes use of artificial intelligence?.
    13·1 answer
  • A ____ risk assessment evaluates threats to and vulnerabilities of the network.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!