Question

For NetBeans Java 8: The bookstore sells items to students, faculty/staff and the public. There are...

For NetBeans Java 8:

The bookstore sells items to students, faculty/staff and the public. There are M visitors and N cashiers in the bookstore at any given time. Visitors typically wander around shopping for items then line up to cash out. Cashiers service visitors on a first come first served basis. Write a program to synchronize the visitors and cahiers using semaphores and/or monitors. Follow the guidelines and instructions below:

- Prompt the user for the values of M and N. Assume an upper bound on M is 50 and N is 10.

- Assume the number of items each person carries to the cashier is between 1 and 6 and that they shop for between 50 to 75 time units per item.

- Assume it takes between 10 and 20 time units for a cashier to checkout an item.

- Show: the number of people shopping, the number of people waiting in the cashier line and the number of people being served.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Cashier{

public static time = Math.random()*((20-10)+1)+10;

}  

class Visitor extends Cashier{  

public static item = Math.random()*((6-1)+1)+1;

public static time = Math.random()*((75-50)+1)+50;

private Semaphore semaphore;

public Visitor(Semaphore semaphore) {
this.semaphore = semaphore;
}

 private void criticalCode()
 {try {
     sleep(item*Cashier.time);
    } catch (InterruptedException e) {
    }
 }

public void run()
{

int count=0;
try {
semaphore.acquire();
criticalCode();
semaphore.release();

count++;
} catch (InterruptedException e) {
System.out.println("Exception " + e.toString());
}

System.out.println("The number of people being served:" + count);

}

}  

public class BookStore{  
public static void main(String args[]){  

Scanner sc = new Scanner(System.in);

int m = sc.nextInt();

int n = sc.nextInt();

Semaphore semaphore = new Semaphore(n, true);
Visitor p[] = new Visitor[m];

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

int count=0;
p[i] = new Visitor(semaphore);

count ++;
p[i].start();
}

System.out.println("The number of people waiting:" + count);

}  
}  

Add a comment
Know the answer?
Add Answer to:
For NetBeans Java 8: The bookstore sells items to students, faculty/staff and the public. There are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Budgeting for an Academic Department at a State University: Can You Believe the Numbers? INTRODUCTION You...

    Budgeting for an Academic Department at a State University: Can You Believe the Numbers? INTRODUCTION You are the senior accounting faculty member in the business school and your dean, Dean Weller, is asking for help. She is very discouraged after a midyear budget meeting with the Vice President of Finance. The college's Department of Social Work has a large budget deficit, and because of this the VP is inclined towards closing the department entirely or closing its bachelor's program. The...

  • 8. Which of the following accounts has a normal debit balance? a. Accounts Payable b. Sales...

    8. Which of the following accounts has a normal debit balance? a. Accounts Payable b. Sales Returns and Allowances c. Sales d. Interest Revenue 9. Using a perpetual inventory system, the entry to record the purchase of $30,000 of merchandise on account would include a a. debit to Sales b. debit to Merchandise Inventory c. credit to Merchandise Inventory d. credit to Sales 10. A retailer purchases merchandise with a catalog list price of $15,000. The retailer receives a 30%...

  • Scenario: Styles Wing Bicycle Company manufactures and sells 2 sizes of bicycles, 21.5 inch and 22.5...

    Scenario: Styles Wing Bicycle Company manufactures and sells 2 sizes of bicycles, 21.5 inch and 22.5 inch. Sales Their sales team has committed to the following projected monthly unit sales for the next year. Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov 21.5 Bike 368 472 633 616 443 345 322 317 317 317 328 22.5 Bike 320 410 550 535 385 300 280 275 275 275 285 Dec 420 365 The selling price for the 21.5...

  • PLEASE SOLVE THESE PROBLEMS! URGENT 8/16/2019 How to Recognize Plagiarism -- Undergraduate Certification Tests : School...

    PLEASE SOLVE THESE PROBLEMS! URGENT 8/16/2019 How to Recognize Plagiarism -- Undergraduate Certification Tests : School of Education, Indiana University Bloomington In the case below, the original source material is given along with a View Site sample of student work. Determine the type of plagiarism by clicking Map the appropriate radio button. Original Source Material Student Version Acknowledge Site Suppose you study a group of successful companies and you find that they emphasize customer focus, or quality improvement, or empowerment;...

  • The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use...

    The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...

  • The following guidelines outline the basic template for a robot vacuum cleaner game. The game must...

    The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT