Question: I only need task2 but it is dependent on task1. please use java language. Task 1 (60 points) In this task, you are supposed to




I only need task2 but it is dependent on task1. please use java language.
Task 1 (60 points) 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 sample input1.txt file content: 1 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. . 2 . 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 takes customer 2 at minute 1 (wait: O mins) Waiter 1 takes customer 1 at minute 1 (wait: O 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: O mins) Waiter takes customer 5 at minute 15 (wait: 11 mins) Waiter 2 takes customer 12 at minute 21 (wait: 4 mins) Waiter takes customer 7 at minute 25 (wait: 16 mins) Waiter 1 takes customer 11 at minute 25 (wait: 10 mins) Waiter 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 customer's (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. 3 Task 2 (40 points) The restaurant bought a fruit stand for the kitchen. That is to be stored in a hash table. The input file, fruits.txt includes all the possible key/fruit combinations that can be inserted into your hash table. There are the real price lookup values for the corresponding fruit. In this task, you are asked to implement a hash table class in Java. You must use your own implementation of hash table by taking inspiration from your textbook or web. You are not allowed to use any external library or .jar file. Your hash table must include the following functions: hashFunction (key): This function takes a key as an argument and returns the address or offset), of the data to be stored. You will need to implement two hash functions: hash with linear probing, and double hashing. Remember that linear probing simply checks for the next available spot in the table, and returns the memory address (or offset). Double hashing uses a personalized increment, and another hash function, to give the first memory address, and if there is a collision, it uses the output of the first function as input for the next function, goes like this... insert (key, data): Accepts the key, and data, as arguments then stores the data. find (key): The find function accepted the key as an argument, and returns the data. delete(key): The delete function removes the specified element from the hash table. To make Task 2 (40 points) The restaurant bought a fruit stand for the kitchen. That is to be stored in a hash table. The input file, fruits.txt includes all the possible key/fruit combinations that can be inserted into your hash table. There are the real price lookup values for the corresponding fruit. In this task, you are asked to implement a hash table class in Java. You must use your own implementation of hash table by taking inspiration from your textbook or web. You are not allowed to use any external library or jar file. Your hash table must include the following functions: hash Function (key): This function takes a key as an argument and returns the address (or offset), of the data to be stored. You will need to implement two hash functions: hash with linear probing, and double hashing. Remember that linear probing simply checks for the next available spot in the table, and returns the memory address (or offset). Double hashing uses a personalized increment, and another hash function, to give the first memory address, and if there is a collision, it uses the output of the first function as input for the next function, goes like this... insert (key, data): Accepts the key, and data, as arguments then stores the data. find (key): The find function accepted the key an argument, and returns the data. delete(key): The delete function removes the specified element from the hash table. To make things easier for you (and because this is after how data is stored in the real world), you will be allowed to mark items as deleted. Note below, you will have a spot for markedDeleted which is O when the item is not deleted, and set to 1 after deleted. Example of deleted item could be: [4133, 'apple gala', 1] rehash(): This function doubles the size of the hash table, and rehashes all the items into their new place into the new larger table. You will be allowed to create a new table (twice the size), to store the new values. (You are not required to add space to the existing table and rehash in place.) printTable(): This function will be performed after inserting, showing your hash function works, and your table can rehash and double in size after the num_elements grows to half the size of the table. To demonstrate your hash table works, your main() function (inside your Tester class) must do the following six steps for each of the two hash function (once using linear probing, and once using double hashing): 1) Pick your 20 favorite fruit from the list provided. 2) Begin with a hash table of size 10. 4 3) Insert your fruit into the table, printing the table (using printTable()) after inserting elements 4,5,9,10,20. You should show your inserts working, and your rehash function working after the table fills up by half. 4) After inserting 20 items, run the find() function on your 3 favorite fruit to show your find function works. 5) Delete your 3 least favorite fruit in the list. As mentioned, marking as deleted is fine. Then run the find() function on these same 3 fruit to show that they are gone. A simple message "item not found" is fine. You do not need to rehash after deleting 3 items. 6) Print your hash table again after the 3 items has been deleted. As a result of your demonstration, you must write your main() output to a txt file as output.txt. Performing above steps is up to you. You may either having multiple hash functions in a single class or have two classes or two separate folders with totally different classes and main() functions. You do not need to prepare PDF report for this task. For a partial output example, after you completed 4 inserts, the hash table should look like: ht = HashTable() ht.insert (4514, "alfalfa sprouts") ht.insert (4131, "apple fuji") ht.insert (4133,"apple gala") ht.insert (4017, "apple granny smith") ht.print Table() [O, "', 0] 14131, 'apple fuji', o 3) Insert your fruit into the table, printing the table (using printTable()) after inserting elements 4,5,9,10,20. You should show your inserts working, and your rehash function working after the table fills up by half. 4) After inserting 20 items, run the find() function on your 3 favorite fruit to show your find function works. 5) Delete your 3 least favorite fruit in the list. As mentioned, marking as deleted is fine. Then run the find() function on these same 3 fruit to show that they are gone. A simple message "item not found" is fine. You do not need to rehash after deleting 3 items. 6) Print your hash table again after the 3 items has been deleted. As a result of your demonstration, you must write your main() output to a txt file as output.txt. Performing above steps is up to you. You may either having multiple hash functions in a single class or have two classes or two separate folders with totally different classes and main() functions. You do not need to prepare PDF report for this task. For a partial output example, after you completed 4 inserts, the hash table should look like: ht = HashTable() ht.insert (4514, "alfalfa sprouts") ht.insert (4131, "apple fuji") ht.insert (4133, "apple gala") ht.insert (4017, "apple granny smith") ht.printTable() [0, "', 0] [4131, 'apple fuji', 0] [0, "', 0] [4133, 'apple gala', 0] [4514, 'alfalfa sprouts', 0] [O",O] [0, "', 0] [4017, 'apple granny smith', 0] [O", 0] [0, 0] The hash table should grow and rehash all elements after the number of elements fills half of the table, in other words num_elements == table_size/2 ht.insert (4218, "apricots") ht.print Table() 5 I' [0," 0] [0, 0] [0, "' 0] [0,0] [O, 0] [0,", 0] [0," , 0] [0, "', 0] [O", 0] [0,", 0] ["', 0] [4131, 'apple fuji', 0] [0, 0] [4133, 'apple gala', 0] [4514, 'alfalfa sprouts', 0] [0, "', 0] [0, "', 0] [4017, 'apple granny smith', 0] [4218, 'apricots', 0] [O", 0]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
