Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions

Question

=+3. How do emotional appeals differ from logical appeals? [LO-2]

Answered: 1 week ago