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
You are the project manager tasked to implement a critical application in a reputed bank. A client review indicates that you cou
Oksana_A [137]
Hiring based on unbais form
6 0
3 years ago
Scripts based on other sources, such as short stories, novels, or biographies, are known as _____.
Sedaia [141]

Answer: adapted screenplays

Explanation:

you’re basing your script based off of other sources and stuff.

8 0
4 years ago
Which of the following best explains the different between Cut and Copy? a. When you copy text you are permanently deleting it,
Vilka [71]
B. When you copy text it remains in its original location and places it on the clipboard. Cutting text removes it from its original location and places it on the clipboard

5 0
3 years ago
Read 2 more answers
Select the correct answer.
dedylja [7]

Answer:

D. MAN

Explanation:

A local area network (LAN) refers to a group of personal computers (PCs) or terminals that are located within the same general area and connected by a common network cable (communication circuit), so that they can exchange information from one node of the network to another. A local area network (LAN) is typically used in small or limited areas such as a set of rooms, a single building, school, hospital, or a set of well-connected buildings. Some of the network devices or equipments used in a local area network (LAN) includes an access point, personal computers, a switch, a router, printer, etc.

On the other hand, a metropolitan area network (MAN) is formed by an aggregation of multiple local area network (LAN) that are interconnected using backbone provided by an internet service provider (ISP). A metropolitan area network (MAN) spans for about 5 kilometers to 50 kilometers in size.

Basically, a metropolitan area network (MAN) spans across a geographic area such as a city and it's larger than a local area network (LAN) but significantly smaller than a wide area network (WAN).

In conclusion, the network type that the patrol services of a city's police department would most likely use is a metropolitan area network (MAN).

6 0
3 years ago
How does a computer find a home group and join it
dezoksy [38]

Answer:

pen the Start menu, do a search for HomeGroup and press Enter.

Click the Join now button. ...

Click Next.

Select the content you want to share on the network by using the drop down menu for each folder and click Next.

Enter your HomeGroup password and click Next.

Explanation:

hope this helps if not ask me :);):):):)

6 0
3 years ago
Other questions:
  • When looking at a poster from the Art Deco movement, what one design characteristic would you most expect to see?
    6·1 answer
  • When choosing a new computer to buy, you need to be aware of what operating _____ a0 it uses.
    6·1 answer
  • Megan has written the following rough draft for her assignment. Choose the correct way to complete each sentence. Sarah is creat
    13·1 answer
  • Diane wants to maintain a record of percent change in sales from the year 2000 to the present year. She enters the values of per
    10·1 answer
  • A call center company wants to implement a domain policy primarily for its shift workers. The call center has large groups with
    11·1 answer
  • In a particular jurisdiction, taxi fares consist of a base fare of $4.00, plus $0.25 for every 140 meters traveled. Write a func
    11·1 answer
  • QUESTION 16
    14·1 answer
  • Which formatting option(s) can be set for Conditional Formatting rules?
    8·2 answers
  • Swapping as applied in memory management with an aid of a diagram​
    13·1 answer
  • Question # 2 Multiple Select You wrote a program to compare the portion of drivers who were on the phone. Which statements are t
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!