Suppose there is only one customer service available in SAMBA Bank in Thursday morning, in every 4 minutes a new customer arrives at the end of waiting line, each customer will need 7 minutes for the service
Write a program to print out the information after the first 60 minutes
[ data structure course, solve in java, please (Hint: use the queue concept )]
Ans:- Java code for the above question using queue
Code:-
import java.util.*;
import java.util.LinkedList;
import java.util.Queue;
public class Customer
{
public static void main (String[] args) throws java.lang.Exception
{
int no_of_users=0,no_of_customer_served=0;
Queue<Integer> q = new LinkedList<>();
for(int i=0;i<60;i+=4)
{
no_of_users++;
//after every four minute the new customer was added to the Queue
q.add(no_of_users);
// It will print the arriving time of every customer
System.out.println("The "+no_of_users+" customer was arrived at "+i+"minute");
}
System.out.println();
int k=0;
for(int i=0;i+7<60;i+=7)
{
k=i+7;
no_of_customer_served++;
//after every seven minute a customer leave the Queue
q.remove();
// It will print the arriving time of every customer
System.out.println("The "+no_of_customer_served+" customer was leaving at "+k+"minute");
}
System.out.println();
// remaining size of queue will tell the number of customer left in queue
System.out.println("The number of customer in the line are "+q.size());
// the customer at the top of the queue will be the current serving customer
System.out.println();
System.out.println("The current serving customer is "+q.peek());
}
}
Output:-
Get Answers For Free
Most questions answered within 1 hours.