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
Dmitry_Shevchenko [17]
3 years ago
9

A single-lane bridge connects village A to village B. Farmers in the two villages use this bridge to deliver their products to t

he neighboring town. The bridge can become deadlocked if a farmer from village A and a farmer from village B get on the bridge at the same time. Using semaphores and/or mutex locks (do not be concerned about starvation) implement your solution in Java. In particular, represent village A and village B farmers as separate threads. Once a farmer is on the bridge, the associated thread will sleep for a random period of time, representing traveling across the bridge.
Business
1 answer:
Nookie1986 [14]3 years ago
5 0

Answer:

Answer: Main Java

Explanation:

code:

Main.java

import java.lang.InterruptedException;

import java.lang.Thread;

import java.util.Random;

public class Main {

   final private static int FARMERS = 10;

   public static void main(String[] args) {

       Bridge bridge = new Bridge();

       Random r = new Random();

       System.out.println("Running with " + FARMERS + " farmers...");

       // Enter a bunch of farmers from different directions.

       for (int i = 0; i < FARMERS; i++) {

           Farmer farmer;

           if (r.nextBoolean()) {

               farmer = new SouthBoundFarmer(bridge);

           } else {

               farmer = new NorthBoundFarmer(bridge);

           }

           cross(farmer);

       }

   }

   private static void cross(Farmer f) {

       new Thread(f).start();

   }

}

SouthBoundFarmer.java

public class SouthBoundFarmer extends Farmer {

   public SouthBoundFarmer(Bridge b) {

       super(b);

       this.name = "South";

   }

}

Farmer.java

import java.lang.InterruptedException;

import java.util.Random;

public class Farmer implements Runnable {

   private Bridge bridge;

   private Random random;

   protected String name;

   public Farmer(Bridge b) {

       this.bridge = b;

       this.random = new Random();

   }

   public void crossBridge(Bridge bridge) {

       System.out.println("[" + this.name + "] Waiting to enter bridge...");

       try {

           bridge.enter();

           System.out.println("[" + this.name + "] Entering bridge...");

           // Crossing bridge...some farmers are fast, others are slow :P

           Thread.sleep(1000 + random.nextInt(9000));

           System.out.println("[" + this.name + "] Leaving bridge...");

       } catch (InterruptedException e) {

           System.out.println("...Interrupted!");

       } finally {

           bridge.leave();

       }

   }

   public void run() {

       this.crossBridge(this.bridge);

   }

}

You might be interested in
Elementary school treachery only need a community college or associates degree
katovenus [111]

That answer is false, because you also need two years of schooling or teaching. Plze mark me brainiest

3 0
4 years ago
Name and explain the relationship between triple bottom line social responsibility
KonstantinChe [14]
The three bottom line in the social responsibility are :

- Economic
- Social
- Environment

This three bottom lines could directly affect each other. For example, as the company experienced an economic growth, it could increase the quality of the social and environmental element around the company through various Corporate social responsibilities.
7 0
3 years ago
The best way to achieve significant increases in interest accrual in a savings account is through
loris [4]
Compounding. If you compound your interest, then your interest rate will go up, and you get more interest.
6 0
3 years ago
When a country's economy is producing at a level that exceeds its potential gdp, the standardized employment deficit will show a
Alla [95]

Answer:

<u>smaller deficit</u>.

Explanation:

A smaller deficit than the current deficit is the ideal answer to fill the gap. A deficit occurs when expenditures are greater than revenues, so in an economy with a surplus, revenues will be larger than expenses, so the standardized employment deficit will be smaller than the current one, because an economy with a GDP that exceeds its potential , is an economy that is expanding, production is larger, which consequently increases the employment rate and decreases the deficit.

5 0
3 years ago
Englewood Company has an opportunity to produce and sell a revolutionary new smoke detector for homes. To determine whether this
Alchen [17]

Answer:

1) Compute the net cash inflow (cash receipts less yearly cash operating expenses) anticipated from the sale of the smoke detectors for each year over the next 12 years.

year              net cash flow

0                   -$140,000

1                    ($20 x 4,000) - $70,000 - $127,500 + $7,500 = -$110,000

2                   ($20 x 7,000) - $70,000 - $127,500 + $7,500 = -$50,000

3                   ($20 x 10,000) - $50,000 - $127,500 + $7,500 = $30,000

4                   ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

5                   ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

6                   ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

7                   ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

8                   ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

9                   ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

10                  ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

11                   ($20 x 12,000) - $40,000 - $127,500 + $7,500 = $80,000

12                  ($20 x 12,000) - $40,000 - $127,500 + $7,500 + $40,000 +

                    $10,000 = $130,000

2) Using the data computed in (1) above and other data provided in the  problem, determine the net present value of the proposed investment.

using a financial calculator, the NPV = -$56,801.13

3) Would you recommend that Englewood Company accept the smoke detector as a new product?

Since the NPV is negative, the project should be rejected.

8 0
3 years ago
Other questions:
  • When Jeff Bezos founded Amazon in 1994, he was laying the foundation for the world’s largest ________, because Amazon uses the I
    9·1 answer
  • Seven-year-old amal understands that when a cookie is broken into three smaller portions, it is still only one cookie, not three
    6·2 answers
  • What is authenticity in the often-used framework of quality criteria?
    15·1 answer
  • PLEASE HELP ME ASAP PLEASE!!!!
    11·1 answer
  • Division X makes a part with the following characteristics:
    11·1 answer
  • There are 10,000 shares of $20 par value cumulative 7 percent preferred stock outstanding, and 90,000 shares of common stock out
    12·1 answer
  • A retirement account in which investments are not tax-deferred but can be
    6·2 answers
  • What low-risk investment can provide Kazuo income when he retires?
    6·1 answer
  • Which of the following statements regarding the income statement columns on the worksheet is false?
    5·1 answer
  • This video speeds through over 10 common mistakes people make that leave them open to identity theft. list at least 5 of them he
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!