Barbershop.java
public class BarberShop{
public static void main (String[] args){
//instance variables
CustomerData next, arriving;
WaitingChairs waitingChair;
ArrivalQueue arrivalQueue;
Barber barber;
int time;
arrivalQueue = new
ArrivalQueue();
arrivalQueue.readFile();
waitingChair = new
WaitingChairs();
barber = new Barber();
time = 0;
while(!arrivalQueue.isEmpty() ||
!waitingChair.isEmpty() || !barber.isEmpty())
{
System.out.println("Time = " + time + "\n");
if(barber.isEmpty() && !waitingChair.isEmpty())
{
barber.addCust(waitingChair.peek());
waitingChair.removeCustomer();
}
if(arrivalQueue.peek().getArrivalTime() == time)
{
if(waitingChair.isFull())
{
System.out.println("All
chairs are full");
System.out.println("\t" +
arrivalQueue.peek().getName() + " leaves");
}
else
{
waitingChair.addCustomer(arrivalQueue.peek());
System.out.println("A chair
is available");
System.out.println("\t" +
arrivalQueue.peek().getName() + " sits");
}
arrivalQueue.removeCustomer();
}
waitingChair.display();
barber.display();
System.out.println("\nArrival List");
arrivalQueue.display();
time++;
barber.performService();
System.out.println("\n-----------------------------\n");
}
}
}
CustomerData.java
public class CustomerData{
//instance variables
private int arrivalTime;
private String name;
private int serviceTime;
private CustomerData next;
//constructor
public CustomerData(int conArrivalTime, int
conServiceTime, String conName)
{
arrivalTime =
conArrivalTime;
serviceTime =
conServiceTime;
name = conName;
next = null;
}
public CustomerData()
{
arrivalTime = 0;
serviceTime = 0;
name = null;
next = null;
}
//methods
public CustomerData getNext()
{
return next;
}
public String getName()
{
return name;
}
public int getArrivalTime()
{
return arrivalTime;
}
public int getServiceTime()
{
return serviceTime;
}
public void setNext(CustomerData
nextCustomer)
{
next = nextCustomer;
}
public void setName(String newName)
{
name = newName;
}
public void setArrivalTime(int
newArrivalTime)
{
arrivalTime =
newArrivalTime;
}
public void setServiceTime(int
newServiceTime)
{
serviceTime =
newServiceTime;
}
public void display()
{
System.out.println("\t" + name + ":
" + "arrival = " + arrivalTime + ':' + " service = " +
serviceTime);
}
public boolean hasNext()
{
return next == null;
}
}
WaitingChairs.java
public class WaitingChairs{
//instance variables
private int numItems = 0;
private int firstCus;
private int lastCus;
private int size = 3;
private CustomerData[] customer;
//constructor
public WaitingChairs()
{
size = 3;
customer = new
CustomerData[size];
lastCus = 0;
firstCus = 0;
}
public static void main (String[] args)
{
WaitingChairs temp = new
WaitingChairs();
temp.display();
CustomerData test = new
CustomerData(1,2,"jon");
temp.addCustomer(test);
temp.display();
CustomerData test2 = new
CustomerData(1,3,"matt");
temp.addCustomer(test2);
temp.display();
//ask how to test peek
}
//methods
public void addCustomer(CustomerData
firstCustomer)
{
if(!isFull())
{
customer[firstCus] = firstCustomer;
firstCus =
(firstCus+1)%size;
numItems++;
}
else
{
System.out.println("Queue is full!");
}
}
public CustomerData removeCustomer()
{
CustomerData lastCustomer =
customer[lastCus];
lastCus = (lastCus+1) %size;
numItems--;
return lastCustomer;
}
public CustomerData peek()
{
return customer[lastCus];
}
public void display()
{
if(!isEmpty())
{
System.out.println("\nChairs");
for(int i = 0;i
< numItems; i++){
customer[(lastCus+i)%size].display();
}
}
else
{
System.out.println("\nChairs are empty");
}
}
public boolean isFull()
{
if(numItems == size)
{
return
true;
}
else
{
return
false;
}
}
public boolean isEmpty()
{
if(numItems == 0)
{
return
true;
}
else
{
return
false;
}
}
}
ArrivalQueue.java
import java.util.Scanner;
import java.io.*;
public class ArrivalQueue{
//instance variables
private int numItems;
private CustomerData firstCustomer;
private CustomerData lastCustomer;
//constructors
public ArrivalQueue()
{
firstCustomer = null;
lastCustomer = null;
numItems = 0;
}
//methods
//test code
public static void main (String[] args)
{
ArrivalQueue test = new
ArrivalQueue();
test.readFile();
test.display();
CustomerData temp = new
CustomerData(1,1, "temp");
test.addCustomer(temp);
test.removeCustomer();
test.display();
//ask how to test peek
}
public void addCustomer(CustomerData
newFirstCustomer)
{
if(firstCustomer == null &&
lastCustomer == null)
{
firstCustomer =
newFirstCustomer;
lastCustomer =
newFirstCustomer;
numItems++;
}
else
{
firstCustomer.setNext(newFirstCustomer);
firstCustomer =
newFirstCustomer;
numItems++;
}
}
public CustomerData removeCustomer()
{
CustomerData c =
lastCustomer;
lastCustomer =
lastCustomer.getNext();
numItems--;
return c;
}
public void display()
{
CustomerData tempCustomer =
lastCustomer;
while(tempCustomer != null)
{
tempCustomer.display();
tempCustomer =
tempCustomer.getNext();
}
}
public CustomerData peek()
{
if(!isEmpty())
return
lastCustomer;
else
{
CustomerData
temp = new CustomerData(1,1, "temp");
return
temp;
}
}
public boolean isEmpty()
{
if(numItems == 0)
{
return
true;
}
else
{
return
false;
}
}
public void readFile(){
String inputLine;
Scanner fileInput;
File inFile = new
File("Barber.txt");
System.out.println("Opening and
reading file");
try{
fileInput = new
Scanner(inFile);
while(fileInput.hasNext())
{
CustomerData temp = new CustomerData();
temp.setArrivalTime(fileInput.nextInt());
temp.setServiceTime(fileInput.nextInt());
temp.setName(fileInput.nextLine());
addCustomer(temp);
}
fileInput.close();
} // end try
catch (FileNotFoundException
e)
{
System.out.println(e);
System.exit(1); // IO error; exit
program
} // end catch
}
}
Barber.java
public class Barber{
//instance variables
private int serviceTime;
private CustomerData customer;
//constructors
public Barber()
{
serviceTime = 0;
customer = null;
}
//methods
public boolean addCust(CustomerData newCust)
{
if(isEmpty())
{
customer =
newCust;
serviceTime =
newCust.getServiceTime();
return
true;
}
else
{
return
false;
}
}
public boolean isEmpty()
{
if(customer == null)
{
return
true;
}
else
{
return
false;
}
}
public void performService()
{
serviceTime--;
if(serviceTime == 0)
{
removeCust();
}
}
public void removeCust()
{
customer = null;
}
public CustomerData peek()
{
return customer;
}
public void display()
{
if(isEmpty())
{
System.out.println("\nBarber's chair is empty");
}
else
{
System.out.println("\nBarber");
System.out.println(customer.getName() + " is chair " + serviceTime
+ " left");
}
}
}
Barber.txt
1 3 Bob
2 2 Jim
4 2 Bert
8 7 Greg
9 3 Tom
10 2 Earl
11 3 Jon
12 2 Bill
JAVA CODE REQUIRED A barber shop has one or more barbers who service customers as they...
17.2-2.* Newell and Jeff are the two barbers in a barber shop they own and operate. They provide two chairs for customers who are waiting to begin a haircut, so the number of customers in the shop varies between 0 and 4. For n 0. 1. 2. 3. 4, the probability P that exactly n customers are in the shop is P0= P, = (a) Calculate L. How would you describe the meaning of L to Newell and Jeff? (b)...
Problem 15-9 (Algorithmic) Marty's Barber Shop has one barber. Customers have an arrival rate of 2.3 customers per hour, and haircuts are given with a service rate of 4 per hour. Use the Poisson arrivals and exponential service times model to answer the following questions: What is the probability that no units are in the system? If required, round your answer to four decimal places. P0 = What is the probability that one customer is receiving a haircut and no...
Benny the Barber owns a one-chair shop. At barber college, they told Benny that his customers would exhibit a Poisson arrival distribution and that he would provide an exponential service distribution. His market survey data indicate that customers arrive at a rate of 2.0 per hour. It will take Benny an average of 22 minutes to give a haircut. Based on these figures, find the following: a. The average number of customers waiting. (Round your intermediate calculations to 3 decimal...
Benny the Barber owns a one-chair shop. At barber college, they told Benny that his customers would exhibit a Poisson arrival distribution and that he would provide an exponential service distribution. His market survey data indicate that customers arrive at a rate of 2.0 per hour. It will take Benny an average of 26 minutes to give a haircut. Based on these figures, find the following: a. The average number of customers waiting. (Round your intermediate calculations to 3 decimal...
Benny the Barber owns a one-chair shop. At barber college, they told Benny that his customers would exhibit a Poisson arrival distribution and that he would provide an exponential service distribution. His market survey data indicate that customers arrive at a rate of 2.0 per hour. It will take Benny an average of 22 minutes to give a haircut. Based on these figures, find the following:The average time a customer waits?
A small barbershop, operated by one barber, has room for only one waiting customer. Potential customers arrive at a rate of 6 people per hour, and it takes an average of 15 minutes for the barber to serve a customer. a) Find the steady state probabilities. b) Find the probability that an arriving customer will be turned away. c) Find the expected number of people in the barbershop. d) Find the expected number of people in the barbershop. e) Find...
Ned's New Wave Barber Shop specializes in modern unisex haircuts. The only service available at Ned's is a “20-minute” haircut for which the customer is charged $10. The shop has five (5) barbers. (Ned does not work in the shop and, as owner/entrepreneur, he takes no salary.) Each barber is paid an annual salary of $18,000. All equipment including store fixtures and barbering equipment is leased on an annual basis at $4,500 per year. Building space is leased at the...
Subject: Broadband Networks. 4. A bank has 4 tellers with different service rates, i.e., teller 1 averages 10 customers/hour, teller 2 averages 15 customers/hour, teller 3 averages 12 customers/hour, and teller 4 averages 10 customers/hour (all with exponential service times). Assume that there are 20 seats in the lobby, and any customer arriving to a fully-occupied lobby leaves. a. If the system is modeled as a Markov chain, what is the total number of states? b. What is the average...
Only need 1-8 01-02 The post office uses a multiple channel queue, where customers wait in a single line for the first ava lable window. If the average service time is I minute and the arrival rate is 6customers every five minutes, find for a 5 minutes perfermance time window, when two service windows are open Q1. the probability that both windows are idle (not busy). a. 0.1765 b. 0.2500 c. 0.5160 d 0.1976 02. the probability a customer will...
1. Generally speaking, which of the following is NOT a common feature of a service organization? a. Quality is not easy to measure in service processes b. Customers are more involved in service processes c. Service processes have less variability d. Satisfaction in services is subjective 2. Which of the following is NOT an assumption made in the queueing model discussed in class? a. The arrival rate can be larger than the service rate b. There is infinite waiting room...