Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develope a Queue ADT . Assume each number in the queue represents a person in a

ID: 3865177 • Letter: D

Question

Develope a Queue ADT . Assume each number in the queue represents a person in a line waiting to be served at your restaurant. Based on historical data, you found that on average, one customer arrives at your restaurant on every five minutes interval, and it takes 3 minutes to serve each customer. Write a tester program to simulate the queue for 8 hours, then print the longest queue size during the 8 hours operation. Did anyone leave your restaurant because the line if full? (assume the maximum capacity of the line is 10 people)

Explanation / Answer

import java.util.ArrayList;

public class QueueCheck {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       ArrayList<Integer> q = new ArrayList<Integer>();
       q.add(1);//1 customer arrives at t=0
       int c=0,max =0;
       for(int t=1;t<=8*60;t++){
           if(t%5 == 0 && q.size()<10) q.add(1);
           if(q.size() == 10){
               c++;
               System.out.println("Queue is full at time = "+t);
           }
           if(q.size()>max) max = q.size();
           if(t%3 == 0 && !q.isEmpty()) q.remove(q.size()-1);
           System.out.println("Queue size at time "+t+" is "+q.size());
          
       }
       System.out.println("Queue was full "+c+" times. Max queue size = "+max);

   }

}

Queue was full 0 times. Max queue size = 1