CS 322 Fall 2013
Project 3
Synchronization
Due Tuesday, November 12th at 10:00 P.M.

Please submit a directory named with your two first names by the deadline on royal
		/Shared/cs322/submit/proj3
It must contain two folders, each with one implementation, and include a readme with

You may work in groups of two. Collaboration within a group is, of course, unrestricted. You may discuss the program with members of other groups, but what you turn in must be your own group's work.

It is a violation to the Honor Code not to acknowledge others' work fully and openly.
You should cite any online resources you consulted to help you solve this project.
You may NOT directly copy any code or any text from anywhere.

Managing a Hair Salon

A hair salon consists of

Life in the salon is all walk-ins. There are no appointments and clients are accepted as they arrive.

The salon operates as follows.

Implementation

Your task is to write two versions of a program that coordinates the stylist and her clients.
Each implementation simulates the daily life of the salon using threads. (The receptionist doesn't deserve a thread of her own. She's just a supporting character.) The number of comfy chairs in the waiting room is determined by an integer passed to the program.
For example
	java HairSalon 5 > output
runs the program using 5 chairs in the waiting room and sends the program standard output to a file.

The user manually enters on the terminal as the program executes

  1. the name of the arriving client and
  2. an integer that is the time needed for the client's cut
    (to simulate the hair cut we may call Thread.sleep(num*1000)).

The application runs until the user enters Ctrl+c on the console.

The application provides informative messages about the simulation, i.e. threads write output as they transit from one state to another.

An example of the console input is

beth 7
sammy 3
felix 4
lise 5
joe 4
aicha 4
mike 3 
alma 5
while the file containing the output produced by the running program is
beth enters the salon.
beth sits down in the waiting room (chair 1).
The stylist reluctantly finishes chatting with the receptionist.
The stylist takes beth inside and starts the hair washing.
sammy enters the salon.
sammy sits down in the waiting room (chair 2).
felix enters the salon.
felix sits down in the waiting room (chair 3).
The stylist finishes cutting beth's hair and blowing it dry (took 7).
beth admires the new hair-style and leaves with a smile.
The stylist takes sammy inside and starts the hair washing.
The stylist finishes cutting sammy's hair and blowing it dry (took 3).
sammy admires the new hair-style and leaves with a smile.
The stylist takes felix inside and starts the hair washing.
lise enters the salon.
lise sits down in the waiting room (chair 2).
joe enters the salon.
joe sits down in the waiting room (chair 3).
The stylist finishes cutting felix's hair and blowing it dry (took 4).
felix admires the new hair-style and leaves with a smile.
The stylist takes lise inside and starts the hair washing.
aicha enters the salon.
aicha sits down in the waiting room (chair 3).
mike enters the salon.
The receptionist tells mike to come back later, and he leaves, grumbling about the wait.
The stylist finishes cutting lise's hair and blowing it dry (took 5).
lise admires the new hair-style and leaves with a smile.
The stylist takes joe inside and starts the hair washing.
The stylist finishes cutting joe's hair and blowing it dry (took 4).
joe admires the new hair-style and leaves with a smile.
The stylist takes aicha inside and starts the hair washing.
alma enters the salon.
alma sits down in the waiting room (chair 2).
The stylist finishes cutting aicha's hair and blowing it dry (took 4).
aicha admires the new hair-style and leaves with a smile.
The stylist takes alma inside and starts the hair washing.
The stylist finishes cutting alma's hair and blowing it dry (took 5).
alma admires the new hair-style and leaves with a smile.
With no waiting clients the stylist resumes gossiping with the receptionist.

Note

When you have finished this assignment you will have written a multi-thread discrete event simulation. Discrete event simulations are used in many computer applications. A few examples,

Resources

Consult the following resources for information about Java threads and concurrency programming.
  1. Java Concurrency Tutorial (Oracle)
  2. Concurrency Programming (Microsoft): Key Rules, slide 22
  3. Java Thread
  4. Java Synchronization
  5. Synchronization Lecture

Grading

This project is graded out of 20 points.

Implementation I
8
Implementation II
8
readme
4