Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(a) Write a Java class to control access to a classroom of 100 students using semaphores, with a first-come, first-served guarantee that students who arrive

(a) Write a Java class to control access to a classroom of 100 students using semaphores, with a first-come, first-served guarantee that students who arrive first are allowed to access the classroom before late arriving students. Your class should have two methods EnterClass and LeaveClass.

(b) Write a main program to test part 2, generating 30 students every 5 minutes. You do not need to write the Student thread class.

(c) Explain why class Q4 below is not thread safe. Re-write it to make it thread safe.

class Q4{

private boolean f[] = new boolean[20];

public Q4(){ for(int j = 0; j < 20; j++) f[j] = true;}

public void negate(int a, int b){

for(int j = a; j < b; j++)f[j] = !f[j]; }

public void swap(int a, int b){

boolean temp = f[a]; f[a] = f[b]; f[b] = temp; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

Explain how cultural differences affect business communication.

Answered: 1 week ago

Question

List and explain the goals of business communication.

Answered: 1 week ago