ABC Inc. sells an item to its clients. Due to the paucity of the item, it has decided to sell 'n' numbers of the item at a time to each client in a sequence in every round. For instance, if n=2, then 2 items are sold to every client in a sequence in the first round. Then, 2 more items are sold to every client in the same sequence in the second round, and so on. This continues till all clients purchase their required number of items, provided the item is available to the seller. Write a Java program to implement this problem using a singly circular linked list. Each node contains the name of the client, its requirement for that item, the remaining item after each purchase, and the waiting time in days. Please see the example of three clients of ABC Inc. below:
Assuming n=5, and the waiting time (w)=2 days:
The initial stage:
Name: XYZ
Total item required: 23
Remaining item: 23
Waiting time in days: 0
Name: MNO
Total item required: 12
Remaining item: 12
Waiting time in days: 0
Name: PQR
Total item required: 34
Remaining item: 34
Waiting time in days: 0
The list after the first round:
Name: MNO
Total item required: 12
Remaining item: 12
Waiting time in days: 2
Name: PQR
Total item required: 34
Remaining item: 34
Waiting time in days: 2
Name: XYZ
Total item required: 23
Remaining item: 18
Waiting time in days: 0
The list after the second round:
Name: PQR
Total item required: 34
Remaining item: 34
Waiting time in days: 4
Name: XYZ
Total item required: 23
Remaining item: 18
Waiting time in days: 2
Name: MNO
Total item required: 12
Remaining item: 7
Waiting time in days: 2
The list after the third round:
Name: XYZ
Total item required: 23
Remaining item: 18
Waiting time in days: 4
Name: MNO
Total item required: 12
Remaining item: 7
Waiting time in days: 4
Name: PQR
Total item required: 34
Remaining item: 29
Waiting time in days: 4
Procedure:
Assume that there is a continuous supply of the item.
When a client is in the first position of the list, subtract n from the remaining item, and send it to the last position of the list.
If a client moves one step forward in the list, add w to the waiting time.
When a client purchases all the required items (i.e., the remaining item is 0), then remove that client from the list. The program will print the name of the removed client and the total waiting time.
When there will be only one client on the list, then keep subtracting n from the remaining item and adding w to the waiting time until the remaining item is 0.
The program will terminate when all clients purchase their required number of items.
The sample input and output are given below:
(25 points)
Sample inputs and outputs:
(User's inputs are shown in bold)
Enter the number of items to be sold to each client at a time: 5
Enter the waiting time in the list: 2
Enter the number of clients: 3
Enter the name of the client 1: XYZ
Enter total requirement: 23
Enter the name of the client 2: MNO
Enter total requirement: 12
Enter the name of the client 3: PQR
Enter total requirement: 34
The client MNO has received all of its required items, and its total waiting time is 10 days.
The client XYZ has received all of its required items, and its total waiting time is 14 days.
The client PQR has received all of its required items, and its total waiting time is 20 days.
DO NOT use ArrayList, LinkedList, or any other built-in Java classes. You can use the Scanner class to take input.
Procedure: Assume that there is a continuous supply of the item.
1. When a client is in the first position of the list, subtract n from the remaining item and send it to the last position of the list.
2. If a client moves one step forward in the list, add w to the waiting time.
3. When a client purchases all the required items (i.e., the remaining item is 0), then remove that client from the list. The program will print the name of the removed client and the total waiting time.
4. When there will be only one client on the list, then keep subtracting n from the remaining item and adding w to the waiting time until the remaining item is 0. The program will terminate when all clients purchase their required number of items.
The sample input and output are given below:
(25 points)
Sample inputs and outputs: (User's inputs are shown in bold)
Enter the number of items to be sold to each client at a time: 5
Enter the waiting time in the list: 2
Enter the number of clients: 3
Enter the name of the client 1: XYZ
Enter total requirement: 23
Enter the name of the client 2: MNO
Enter total requirement: 12
Enter the name of the client 3: PQR
Enter total requirement: 34
The client MNO has received all of its required items, and its total waiting time is 10 days.
The client XYZ has received all of its required items, and its total waiting time is 14 days.
The client PQR has received all of its required items, and its total waiting time is 20 days.
DO NOT use ArrayList, LinkedList, or any other built-in Java classes. You can use the Scanner class to take input.