lab7
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lab7 [2018/03/11 23:19] – franck | lab7 [2019/03/14 01:13] (current) – franck | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Lab 7 ====== | ====== Lab 7 ====== | ||
- | In this lab, we consider | + | You are asked to implement |
- | <code java> | + | |
- | /** | + | |
- | * A stack. | + | |
- | * | + | |
- | * @author | + | |
- | */ | + | |
- | public class Stack { | + | |
- | private int[] content; | + | |
- | private int size; | + | |
- | /* | + | The barber has one barber' |
- | | + | |
- | */ | + | |
- | private final static int CAPACITY = 5; | + | |
- | /** | + | Each customer, when they arrive, looks to see what the barber is doing. |
- | * Initializes this stack to be empty. | + | |
- | */ | + | |
- | public Stack() { | + | |
- | this.content = new int[Stack.CAPACITY]; | + | |
- | this.size = 0; | + | |
- | } | + | |
- | /** | + | The waiting room is represented by the class WaitingRoom and the barber and the customers are represented by Barber and Customer threads. |
- | * Pushes | + | |
- | * | + | |
- | * @param value the integer to be pushed onto this stack. | + | |
- | */ | + | |
- | public void push(int value) { | + | |
- | this.content[this.size] = value; | + | |
- | this.size++; | + | |
- | System.out.printf(" | + | |
- | } | + | |
- | /** | + | Since randomization is used in some of the classes, different runs of the app may produce different outputs. |
- | * Pops the top of this stack and returns | + | < |
- | * | + | Barber sleeps |
- | * @return the top of this stack. | + | Customer 4 enters |
- | */ | + | Customer 4 sits down |
- | | + | Barber wakes up |
- | | + | Customer 4 gets a haircut |
- | int value = this.content[this.size]; | + | Customer 4 leaves |
- | | + | Customer 3 enters |
- | | + | Customer 3 sits down |
- | } | + | Customer 1 enters |
- | } | + | Customer 1 sits down |
+ | Customer 3 gets a haircut | ||
+ | Customer 3 leaves | ||
+ | Customer 0 enters | ||
+ | Customer 0 sits down | ||
+ | Customer 2 enters | ||
+ | Customer 2 sits down | ||
+ | Customer 1 gets a haircut | ||
+ | Customer 1 leaves | ||
+ | Customer 0 gets a haircut | ||
+ | Customer 0 leaves | ||
+ | Customer 2 gets a haircut | ||
+ | Customer 2 leaves | ||
+ | Barber is done for the day | ||
</ | </ | ||
+ | In the above run, there are never more than three customers in the waiting room and therefore all customers get a haircut. | ||
+ | < | ||
+ | Barber sleeps | ||
+ | Customer 1 enters | ||
+ | Customer 1 sits down | ||
+ | Barber wakes up | ||
+ | Customer 2 enters | ||
+ | Customer 2 sits down | ||
+ | Customer 3 enters | ||
+ | Customer 3 sits down | ||
+ | Customer 4 enters | ||
+ | Customer 4 leaves because no chair is free | ||
+ | Customer 0 enters | ||
+ | Customer 0 leaves because no chair is free | ||
+ | Customer 1 gets a haircut | ||
+ | Customer 1 leaves | ||
+ | Customer 2 gets a haircut | ||
+ | Customer 2 leaves | ||
+ | Customer 3 gets a haircut | ||
+ | Customer 3 leaves | ||
+ | Barber is done for the day | ||
+ | </ | ||
+ | In the above run, customers 4 and 0 leave before getting a haircut since all chairs in the waiting room are occupied. | ||
- | Implement the following classes. | + | To receive feedback, submit your code **before** March 23 using the submit command:\\ |
- | * The class Pusher. | + | |
- | * The class Stack. | + | |
- | * The class Main. This class only contains a main method. | + | |
- | + | ||
- | To receive feedback, submit your code using the submit command:\\ | + | |
< | < | ||
submit 4315 lab7 <name of class> | submit 4315 lab7 <name of class> |
lab7.1520810377.txt.gz · Last modified: 2018/03/11 23:19 by franck