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
Caplico Company has prepared the following sales budget:
hichkok12 [17]

Answer:

1.b 2.a

Explanation:

7 0
4 years ago
Read 2 more answers
TeaForMe is a tea company that considered branching out into the snack food business. The TeaForMe team offered many new ideas s
musickatia [10]

Answer:

In the new-product development process, the TeaForMe company is in the idea screening stage

Explanation:

The new-product development process has 8 stages that are:

-Idea generation: is when the company looks for new ideas.

-Idea screening: the company evaluates the ideas and filters them to drop the bad ones and pick the good ones.

-Concept development and testing: is when the company develops and evaluates the product concept.

-Marketing strategy: the company creates the marketing strategy to introduce the product to the market.

-Business analysis: the company evaluates if the idea is a good business.

-Product development: is when the concept is developed into a physical product.

-Test marketing: the company evaluates the product and the marketing strategy in the market.

-Commercialisation: this refers to launching the product to the market.

According  to this, the answer is that in the new-product development process, the TeaForMe company is in the idea screening stage because they generated a new idea an then, evaluated that idea and decided to drop it because it was inconsistent with the organization's new-product strategy.

5 0
3 years ago
A bakery sold apple pies for $11 and blueberry pies for $13. one saturday they sold a total of 38 pies and collected a total of
Nimfa-mama [501]
So first you know that if a is apple pies and b is blueberry that
$460=11a+13b in terms of price and you also know that the number
a+b=38
I solved that for either a or b (I chose a)
So
A=38-b
Them I plugged it in to the money equation to solve for b
460=11(38-b)+13b
460=418-11b+13b
460=418+2b
42=2b
B=21
Therefore you can do 38(total pies)-21(what b equals) to find the apple pies which would be 17 so a=17
Therefore the answer is B (17 apple and 21 blueberry)
5 0
3 years ago
Read 2 more answers
Accounts receivable arising from sales to customers amounted to $80,000 and $70,000 at the beginning and end of the year, respec
Oksana_A [137]

Answer:

$250,000

Explanation:

Calculation for the cash flows from operating activities to be reported on the Statement of Cash Flows

Using this formula

Cash flows=Income Statement+(Accounts receivable arising from sales)

Let plug in the formula

Cash flows=$240,000 +($80,000-$70,000)

Cash flows=$240,000 +$10,000

Cash flows=$250,000

Therefore the cash flows from operating activities to be reported on the Statement of Cash Flows is $250,000

6 0
3 years ago
Barbara's Bakery purchased three new 7-year assets last year. She chose NOT to use Section 179 immediate expensing or take bonus
frez [133]

Answer:

$ 4,748

Explanation:

The depreciation expenses = $(\$ 15000 \times 17.85 \%) + (\$ 6000 \times 10.71 \%)+(\$ 40000 \times 3.57 \%)$

$= \$ 2677.50 + \$ 642.6 + \$ 1428$

= $ 4748

Generally we have use half year convention for assets that are purchased during the year but here we used the mid quarter as of more than the 40% of the assets are being purchased in last quarter of the year

$=\frac{\text{assets purchased in last quarter}}{\text{total assets purchased in the year}} \times 100$

$=\frac{40000}{61000} \times 100$

$=65.57 \%$ (it is more than 40%)

Thus we can use the mid quarter mars depreciation rates for the 7 years assets that are purchased this year.

8 0
3 years ago
Other questions:
  • If Huy Fong were to introduce a new milder version of its renowned Sriracha hot chili sauce to satisfy customers who think the c
    12·1 answer
  • The Traffic Court of King James County operates between the hours of 9AM and 1PM. Each morning, roughly at 9AM, 200 defendants s
    7·1 answer
  • Which concurrent testing method helps calculate the visibility of an outdoor advertisement?
    12·2 answers
  • In this statement, which type of spending is President
    5·2 answers
  • Each business unit has marketing and other specialized activities (e.g., finance, manufacturing, or research and development) at
    6·2 answers
  • Blossom Company began the year with retained earnings of $390000. During the year, the company recorded revenues of $489000, exp
    14·1 answer
  • For services rendered, an attorney accepts a 90-day note for $5,500 at 8% simple interest from a client. (Both interest and prin
    7·1 answer
  • Exhibit 22-8 Above shows how output changes as the only one variable input, labor, changes. At what unit of labor does diminishi
    5·1 answer
  • The following information was drawn from the Year 1 accounting records of Ozark Merchandisers: Inventory that had cost $15,000 w
    13·1 answer
  • When the businesses within an organization share some resources and technologies and each business generates less than 40 percen
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!