Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For NetBeans Java 8: The bookstore sells items to students, faculty/staff and th

ID: 3724688 • Letter: F

Question

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.

Explanation / Answer

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;
}

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);

}  
}  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote