Program 4: Deli Line Simulator

Due Date and Submission Requirements


The goal of this lab is:


Background and Directions

Route 406 is a Subway-style sandwich stand in Miller Dining Hall. In this assignment, you will write a java program that simulates the waiting line for Route 406. Each person waiting in line is represented by a Customer object. You will use a queue data structure that will hold Customer objects.

Each customer has a name, their order (a single String), and the time that they entered the queue (a Long). Your Queue data structure can use a Linked List, or an Array (but I highly recommend using a Linked List).

Students and Professors can enter the queue. Students have to be added to the back of the queue, but when professors are added to the queue, they get to cut in front of all the students and go to the front of the queue.

When a Customer leaves the queue, you will need to calculate how long (in seconds) they were in the queue. You also will need to keep track of the average waiting time for the queue, and the number of customers served.

Your program will have a menu that prints out different options (just like program 3), that allows the user to view, add, and remove customers from the queue.

1. View Current Queue- Shows all the current customers waiting in line. The front of the queue gets printed first, and the back of the queue gets printed last. Sample output
2. Add a student to queue- Adds a new student to the back of the queue. The program should ask for the name of the student, their order, and then insert the Customer object into the queue.Sample output
3. Add a professor to the queue - Adds a new professor to the front of the queue. The professor can cut in front of other students, but not other professors. The program should ask for the name of the professor, their order, and then insert the customer object into the queue. Sample output
4. Serve next customer- Removes the customer at the front of the queue. Once the customer is removed from the queue, the program should print out how long (in seconds) that customer waited in line for (if this number is rounded up/down to the nearest integer, that is fine). Sample output
5. Remove Customer from queue- A customer may grow inpatient, and exit the queue. The program will ask for the name of the customer that needs to be removed, and then remove them from the queue. It should print out how long they waited in line for, but this does not contribute towards the average wait time. Sample output
6. Print Queue Statistics - This methods prints out the number of customers served so far (ie the number of Customers that have been dequeued), and the average wait time of the queue. For example, suppose four customers have been served so far. Customer 1 waited 32 seconds, customer 2 waited 40 seconds, and customer 3 waited 21 seconds and customer 4 waited 16, the average wait time of the queue is (32 + 40 + 21 + 16) / 4 = 27.25 seconds. Sample output (note: in this example, 4 customers were served, and they had wait times of 54, 15, 38 and 17 seconds.
7. Exit - this method exits the program

Restrictions

Sample Output

Your output does not need to match this exactly, but it should look pretty similar. Here is sample output after using several of the menu functions: sample output

Optional Hints

You should use a linked list to hold the Customer objects. Using an Array will be difficult since Customers in the middle of the queue can leave at any point.

I would recommend having two queues. One for professors, and one for students. Adding a professor will add the professor queue (FIFO), and adding a student will add the student queue (FIFO). When you dequeue something, you should prioritize removing the professor queue. If the professor queue is empty, then you can remove something from the student queue.

Tracking the time spent in the queue and calculating the average wait time will likely be the most tricky part. We will cover how to measure and calculate time in Java in class, but here is a general way of how to do so:

We get the current time (in nano seconds) when they enter the queue. When they exit the queue, we will get the current time again (in nanoseconds). To find how long they were in the queue for, we simply find the difference between these two values. You will need to convert nanoseconds to seconds ( / 1000000000)
long start = System.nanoTime();
// some time passes
long end = System.nanoTime();
long elapsedTime = end - start;

Grading (100 points)

Requirement Points
Your program uses a queue (Linked List or Array) to hold Customer objects. 30
Your program can print out the current customers in the queue (Menu option #1) 10
Your program can add a new student customer to the queue correctly (Menu option #2) 10
Your Program can add a new professor customer to the queue correctly (Menu option #3) 10
Your program dequeues the next customer correctly (Menu option #4) 10
Your program can allow a use to search for a customer in the queue by name, and remove that customer (Menu option #5)   10
Your program prints out the number of customers served, and the average wait time correctly (Menu option #6) 10
The Customer class is correctly defined 10






program 4 solution