Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Sleeping Teaching Assistant A university computer science department has a teaching assistant (TA) who helps undergraduate students with their programming assignments during regular office

The Sleeping Teaching Assistant

A university computer science department has a teaching assistant (TA) who helps undergraduate students with their programming assignments during regular office hours. The TAs office is rather small and has room for only one desk with a chair and computer. There are three chairs in the hallway outside the office where students can sit and wait if the TA is currently helping another student. When there are no students who need help during office hours, the TA sits at the desk and takes a nap. If a student arrives during office hours and finds the TA sleeping, the student must awaken the TA to ask for help. If a student arrives and finds the TA currently helping another student, the student sits on one of the chairs in the hallway and waits. If no chairs are available, the student will come back at a later time.

Using threads and semaphores, implement a solution in JAVA that coordinates the activities of the TA and the students.

1. Create n students, each will run as a separate thread.

2. Student threads will alternate between programming for a period of time and seeking help from the TA.

3. If the TA is available, students will obtain help

4. If the TA is not available, students will sit in a chair in the hallway (waitList)

5. If no chairs are available, students will resume programming and seek help at a later time

6. If the TA is sleeping, the student will notify TA with a semaphore

7. Use a semaphore to indicate a student in help mode

8. When a TA finishes helping a student, the TA must check to see if there are students waiting for help in the hallway.

9. The TA must help the students waiting in the hallway in the order that they started waiting.

10. If no students are waiting, then the TA can resume napping.

The best option for simulating students programming as well as the TA providing help to a student is to have appropriate threads sleep for a random period of time.

Make sure your output includes when the semaphores acquire permits and release permits, displays current mode (programming or getting help), and TA is sleeping or helping which student.

The code needs to be in JAVA

-------------------------------------------------- Sample output

*******Output 1************* TA sleeping, no students need help TA waiting for students to notify start . . . first student start . . . third student start . . . second student start . . . fourth student fourth student in programming mode third student in help mode first student in programming mode third student being helped second student in programming mode start . . . fifth student fifth student in help mode TA waking up fifth student in help mode fifth student being helped TA assisting third student TA waking up fourth student in help mode fourth student being helped TA waking up second student in help mode second student being helped TA waking up TA sleeping, no students need help TA waiting for students to notify first student in help mode first student being helped TA waking up TA Done Assisting fifth student in help mode fifth student being helped TA waking up 

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

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

ISBN: 0201844524, 978-0201844528

More Books

Students also viewed these Databases questions