Question: Write a program that simulates the customers waiting in line at a bank. Use a queue data structure to represent the line. As customers arrive

Write a program that simulates the customers waiting in line at a bank.

Use a queue data structure to represent the line.

As customers arrive at the bank, customer objects are put in the rear of the queue with an enqueue operation.

Randomly determine when new customers (1 to 10 customers at a time) arrive at the bank.

When the teller is ready to service a customer, the customer object is removed from the front of the queue with a dequeue operation.

Randomly determine current customers (1 to 10 customers at a time) are served at the teller window.

In each cycle, print a message when an operation occurs during the simulation. Repeat above at least 10 times (cycles).

When the customers are still in the queue, they must be served(dequeued).

Here's the Queue interface and linked queue interface

public interface QueueInterface { public void enqueue(T newEntry); public T dequeue(); public T getFront(); public boolean isEmpty(); public void clear(); }

public final class LinkedQueue implements QueueInterface { private Node firstNode; private Node lastNode; public LinkedQueue(){ firstNode = null; lastNode = null; } @Override public void enqueue(T newEntry){ Node newNode = new Node(newEntry, null); if(isEmpty()) firstNode = newNode; else lastNode.setNextNode(newNode); lastNode = newNode; } @Override public T getFront(){ if (isEmpty()) return null; else return firstNode.getData(); } public T dequeue(){ T front = getFront(); firstNode.setData(null); firstNode = firstNode.getNextNode(); if(firstNode == null) lastNode = null; return front; } @Override public boolean isEmpty(){ return (firstNode == null) && (lastNode == null); } @Override public void clear(){ firstNode = null; lastNode = null; } private class Node{ private T data; private Node next; private Node(T dataPortion){ data = dataPortion; next = null; } private Node (T dataPortion, Node linkPortion){ data = dataPortion; next = linkPortion; } private T getData(){ return data; } private void setData(T newData){ data = newData; } private Node getNextNode(){ return next; } private void setNextNode(Node nextNode){ next = nextNode; } } }

it should look something like this:

Customer 0 joins the line

Customer 1 joins the line

Customer 2 joins the line

Customer 3 joins the line

Customer 0 is being served

Customer 1 is being served

Customer 4 joins the line

Customer 2 is being served

Customer 3 is being served

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!