Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 1 (60 points) Urgent!!Please write the code in java with comments and the output as well In this task, you are supposed to implement

Task 1 (60 points) Urgent!!Please write the code in java with comments and the output as well

In this task, you are supposed to implement a Java program for the scheduling problem of a famous Sabr-ET restaurant by using heap-based priority queue. The manager is trying to find how many waiters work in the service part of the restaurant. For each waiter in the service, the expense of the restaurant increases; but according to the standards of the restaurant, the average waiting time for all customers should not exceed a given amount of time. So, the manager needs to optimize this number and calls for your help in this task. The restaurant has the data of predict service time of customers. Your program should use these data to calculate average waiting times and find the minimum number of waiters needs to meet the average waiting time requirement. You must use your own implementation of heap-based priority queue by taking inspiration from your textbook or web. You are not allowed to use any external library or .jar file. The input data are stored in a plain .txt file. The first line of the file shows the number of customers. The subsequent lines contain four integers, each separated by one or more whitespace characters (space or tab). These represent, respectively, the customer id, the registration year of the customer to the restaurant (the restaurant was founded in 1968), arrival time for meal (in minutes from a given point, e.g. 12:00 am) and service time (in minutes). Here is the sampleinput1.txt file content: 2 12 1 1994 1 10 2 1974 1 14 3 2004 1 6 4 2004 1 5 5 1994 4 10 6 1974 7 14 7 1994 9 10 8 1974 11 14 9 2004 13 6 10 2004 14 5 11 1994 15 10 12 1974 17 14 For example, from the sampleinput1.txt file content above, it is seen that there are 12 customers. The first customer with id 1 arrives at the restaurant at minute 1, and his meal lasts for 10 minutes. He has been a customer of the restaurant for 26 years (e.g. 1994 - 1968). The sixth customer with id 6 arrives at the restaurant at minute 7, and his meal lasts for 14 minutes. He has been a customer of the restaurant for 20 years (1994 - 1974). The seventh customer with id 7 arrives at the restaurant at minute 9, and his meal lasts for 10 minutes. The first and seventh customers have a customer of the restaurant for 26 years, which means that their priorities are the same. You are asked to write a simulation program that reads customer data from sampleinput1.txt file and calculates the minimum number of waiters required for a given maximum average waiting time. The restaurant assigns priority to its customers in order to provide them some special benefits. One of them is that they do not have to wait in the queue for meal service. The priority is defined considering the period of time that a customer has been with the restaurant. Long-time customers of the restaurant have higher priority than others. Your implementation must obey the following requirements: There may be at most 200 customers in the data file. The customer with the highest priority should be examined first. In case of having two customers with the same highest priority, the customer who has waited longer should be selected first. If more than one waiter is available at a given time; the customer is assigned to the waiter with a lower id. When a waiter starts giving a service to a customer, the waiter should finish his service with this customer even though another customer with a higher priority comes to the restaurant. Once a customer is assigned to a waiter, the waiter immediately starts carrying out the service of that customer and is not available during the service time given for that customer. After the service of that customer carries out, the waiter becomes available immediately. 3 The waiting time of a customer is the duration (difference) between the arrival time of the customer and the time he is assigned to a waiter. In your implementation, you must use a heap-based priority queue to store customers who are waiting for a waiter (i.e., to store customers who have arrived at the restaurant but their services have not been conducted yet). If you do not use such a heap-based priority queue to store these customers, then you will get no points from this task of homework. The console output for the sampleinput1.txt file is given as follows. The name of the input file and the maximum average waiting time will be provided as two command line arguments to your program. Your program should calculate the minimum number of waiters required for meeting this maximum average waiting time. Please check your program with this input file as well as the others that you will create. Please note that we may use other input files when grading your assignments. >java MySimulator sampleinput1.txt 10 Minimum number of waiters required: 3 Simulation with 3 waiters: Waiter 0 takes customer 2 at minute 1 (wait: 0 mins) Waiter 1 takes customer 1 at minute 1 (wait: 0 mins) Waiter 2 takes customer 3 at minute 1 (wait: 0 mins) Waiter 2 takes customer 6 at minute 7 (wait: 0 mins) Waiter 1 takes customer 8 at minute 11 (wait: 0 mins) Waiter 0 takes customer 5 at minute 15 (wait: 11 mins) Waiter 2 takes customer 12 at minute 21 (wait: 4 mins) Waiter 0 takes customer 7 at minute 25 (wait: 16 mins) Waiter 1 takes customer 11 at minute 25 (wait: 10 mins) Waiter 0 takes customer 4 at minute 35 (wait: 34 mins) Waiter 1 takes customer 9 at minute 35 (wait: 22 mins) Waiter 2 takes customer 10 at minute 35 (wait: 21 mins) Average waiting time: 9.83333 minutes As a hint, you use the heap data structure to hold customers that are waiting for a waiter and to find the customer with the highest priority. Update the heap whenever a new customer arrives or a customers (meal) service is conducted. In order to find the optimum number of waiters needed, repeat the simulation for increasing number of waiters and return the minimum number of waiters that will achieve the maximum average waiting time constraint. Display the simulation for which you find the optimum number of waiters.

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions