The Sleepy Salon

Three hairdressers work independently in a salon shop:

The salon has 3 salon chairs, each of which is assigned to one hairdresser.

Due to budget restrictions, there are only 2 combs and 2 scissors in the salons.

Each hairdresser follows the same work plan:

- The hairdresser sleeps when no customer is in waiting (and is not in the hairdresser’s own chair).

- When the hairdresser is asleep, the hairdresser waits to be awakened by a new customer. (a sign in the shop indicates which salon has asleep longest, so the customer will know which hairdresser to awake up if multiple hairdressers are asleep.)

- Once awake, the hairdresser cuts the hair of a customer in the hairdresser’s chair.

- The hairdresser requires a comb and a pair of scissors to cut a customer’s hair. When the haircut is done, the customer pays the hairdresser and then is free to leave.

- After receiving payment, the hairdresser calls the next waiting customer (if any). If such a customer exists, that customer sits in the hairdresser’s chair and the hairdresser starts the next haircut, if no customer is waiting, the hairdresser goes back to sleep.

Each customer follows the following sequence of events:

- When the customer first enters the salons, the customer leaves immediately if more than 20 people are waiting (10 standing and 10 sitting). On the other hand, if the salon is not too full, the customer enters and waits.

- If at least one hairdresser is sleeping, the customer looks at a sign, wakes up the hairdresser who has been sleeping the longest, and sits in that hairdresser’s chair (after the hairdresser has stood up).

- If all hairdressers are busy, the customer sits in a waiting-room chair, if one is available. Otherwise, the customer remains standing until a waiting-room chair becomes available.

- Customers keep track of their order, so the person sitting the longest is always the next customer to get a haircut.

- Similarly, standing customers remember their order, so the person standing the longest takes the next available waiting-rom seat.


Simulate each hairdresser and each customer as a separate process.

Altogether, 30 customers should try to enter.

Use a random number generator, so a new customer arrives every 1,2,3 or 4 seconds. (this might be accomplished by an appropriate statement sleep (1+(rand()%4)).

Similarly, use a random number generator, so each haircut lasts between 3 and 6 seconds.

Each hairdresser should report when he/she starts each haircut and when he/she finishes each haircut.

Each customer should report when he/she enters the salon. The customer also should report if he/she decides to leave immediately.

Similarly, if the customer must stand or sit in the waiting room, the customer should report when each activity begins.

Finally, the customer should report when the haircut begins and when the customer finally exits the shop.

Sample output

In order to see what is happening dynamically you must have output from the customers and the hairdressers reporting all their major events.

Add information about which process/thread is doing the output. This way you can see if a process/thread acts for another, which is strictly forbidden, but is a common error for Java solutions (objects are not processes!). An example of such incorrect behaviour is

Thread-Hairdresser: 21.31: Hairdresser1: Customer 3 is done!

Main: 21:50: Hairdresser: Next customer please!

Thread-Customer-12: 21.50: Customer12 is waiting for a chair.

Thread-Hairdresser: 21.31: Hairdrsser2: Acquiring comb2!

Where you can see that not only the hairdresser thread but also the main thread is acting for the hairdresser.

Note that realistic stamps are not required, it is fine to use any function to generate them.

You must not

- Kill a thread or process. You may not use any of the following primitives in Java:

- [url removed, login to view]

- [url removed, login to view]

- [url removed, login to view]

- [url removed, login to view]

- setDaemon

Kemahiran: Java

Lihat lagi: what is resume, track deliverables, thread up, sleepy's, sample of a resume, sample it resume, number sequence solutions, keep track of customers, it resume sample, example resume, example of resume, example of a resume, doing a/resume, doing a resume, c# report generator, sleep salon, the other, sleeping, shop plan, scissors, salon, rom, rom -, kill random, java thread

Tentang Majikan:
( 1 ulasan ) Karachi, Malaysia

ID Projek: #1601028

Dianugerahkan kepada:


Hi, Experienced Java developer for your service. Please approve the Bid. Regards,

$30 USD dalam sehari
(14 Ulasan)