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
The demand for land, labor, and capital used to produce a good depends on which of the following factors?
marysya [2.9K]
D) the availability of land, labor and capital


I think
8 0
3 years ago
On June 1, 2015, Ivanhoe Company and Shamrock Company merged to form Bridgeport Inc. A total of 752,000 shares were issued to co
kompoz [17]

Solution:

a-1) Calculation of the number of shares used for calculating Basic Earning per share    

No. of shares                         period        

752000                                    3/12                           188000    

1314000                                    9/12                           985500    

Weighted average No of shares outstanding   1173500

a-2) Calculation of the number of shares used for calculating Diluted Earning per share    

                        No. of shares                 period        

                          752000                   3/12                 188000                                     1314000                    3/12                  328500      with Bonds       1340400                    6/12                670200      

Weighted average No of shares outstanding           1186700   

Each bonds to per converted into 44 common stock

i.e. 600 Bonds *44 common=26400 Potential equity shares

b-1) Calculation of earning figures to be used for calculating Basic Earning per share    

After Tax net Income will be earnings = $1614000      

b-2) Calculation of earning figures to be used for calculating Diluted Earning per share    

After tax net Income                                                   1614000      

Interest for the 2017 =600000*7*6/12   21000      

Tax effect on Interest @40%                     8400      12600                                                                                                 1626600

Earnings = 1626600      

7 0
3 years ago
________ for forecasting relies on the assumption that underlying relationships in the past will continue into the future, resul
Nitella [24]

Answer: The answer is Trend extrapolation

Explanation:

7 0
2 years ago
A manager invests $20,000 in equipment that would help the company reduce it's per unit costs from $15 to $12. He expects the eq
yKpoI14uk [10]

Since the cost of $20,000 has been incurred two years ago, the firm should check and see as to how many units of the product were produced in the two years. Did the firm produce enough items to break even the cost of acquisition. Additionally the business should also check the current market value of this two year old equipment. The business manager should weigh in the savings that is to be obtained from outsourcing along with the resale value of the old machine and then take a declension as to whether the company should go for outsourcing. Also, the business manager must examine whether the outsourcing can happen for the long run. This is because two years down the line, outsourcing may have increased the cost and again another process may look attractive. So a through cost benefit analysis should be made before taking a decision.

6 0
3 years ago
After obtain a licens,a license must comply with the dbo ommisioner rules and regulations, which is true regarding the finance l
bonufazy [111]

Answer:

True

Explanation:

This is true that no person shall engage in the business of finance broker  or finance lender without obtaining a license from the commissioner. All of them shall comply with dbo rules and regulation. if they fail to comply they may face a fine or cancelation of license.

3 0
3 years ago
Other questions:
  • Which of the following best describes credit sales? Multiple Choice Cash sales to customers that are new to the company. Sales t
    13·2 answers
  • When checking your vehicle during the inspection which of these statements is true
    14·1 answer
  • Why might some firms voluntarily pay workers a wage above the market equilibrium
    9·1 answer
  • April's colleague Nathan has consistently pestered her to go out on a date with him. Though she has refused his offer several ti
    14·1 answer
  • Economic leverage occurs when a business uses it economic power to:
    11·1 answer
  • According to classical macroeconomic theory, changes in the money supply affect: _________.(i) nominal variables, but not real v
    15·1 answer
  • How has MTV networks international overcome cultural difference to create a world band
    5·1 answer
  • ADP reports the following income statement.
    12·1 answer
  • Find the accumulated value of $ 740 at the end of 7 years using a nominal annual rate of interest of 6 % compounded quarterly.
    6·1 answer
  • Name one of the three different levels at which an organization can be diagnosed?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!