Starting from:

$40

Programming (Concurrent programming) Assignment Set 1 Solved

 

Assignment Set 1 (Concurrent programming) 
Problem 1: Merchandise sale for Alcheringa 2020 
The organizers of Alcheringa 2020 are planning to sell its merchandise. Write a program in java to assist the merchandise sale by collecting and processing orders. Consider the following for the system.

i.               The merchandise includes T shirts (of sizes S, M and L) and caps.

ii.             A student can order only one item (either T shirt or cap) in a single order, but in any quantity.

iii.            To simulate multiple orders at the same time, consider taking input in batch and process them together.  

iv.            Use the concept of concurrency and multithreading to process the orders of the batch concurrently.

v.              Display the inventory list to the user before the order.

vi.            An order is successful if sufficient quantity of the item is available, otherwise it is failed.

vii.           Use synchronization to avoid inconsistency in the inventory data.

viii.         Once the order is completed (successful or failed), the status is displayed to the user immediately along with the new inventory list.

            Sample Input: 

            Number of students ordering:  3

1   S 5

2   C 3  

3   M 2

            [Sà T shirt small, Mà T shirt medium, Là T shirt large, Cà Cap]

            Output: 

            Inventory --  

S
M
L
C
4
5
2
4
                

            Order 2 is successful

Inventory --  

S
M
L
C
4
5
2
1
             

            Order 1 failed

            Inventory --  

S
M
L
C
4
5
2
4
             

            Order 3 successful

            Inventory --  

S
M
L
C
4
3
2
4
 

Write a brief report on the following:

 Specify the synchronization technique that you used in the program. Explain your implementation using code snippets.

 

Problem 2: Cold Drink Manufacturing  
  

A cold drink manufacturing factory has a unit which takes care of packaging and sealing the bottles. The arrangement of the sub-units (packaging and sealing) is shown in the above figure. Consider the following points:

i.               The packaging unit wraps a plastic cover to the bottle and the sealing unit seals the bottle with a cap

ii.             Both the above units take the bottles from the unfinished tray (tray containing bottles which are neither packaged nor sealed)

iii.            The packaging unit receives two types of bottles B1 and B2. There are two trays from which bottles are supplied to packaging unit. Each tray contains only one type of bottle  

iv.            The tray which carries bottles of type B1 has a capacity of two and the tray which carries bottles of type B2 has a capacity of three.

v.              The packaging unit identifies and chooses appropriate package for the bottle. This unit can pack one bottle at a time.  

vi.            The sealing unit is used to seal a bottle irrespective of its type. It has a buffer tray of size two. It can accommodate both types of bottle.  

vii.           The order in which processing can occur between the above two units is random. The bottles are sent to the godown once the packaging and sealing are over.

viii.         The priority of the trays containing bottles is higher than that of the unfinished tray.

ix.            The number of bottles processed in each unit and those in the godown is stored in the database.

x.              The program should be written in such a way that the packaging and sealing units should incur minimum idle time.

xi.            The time to package a bottle takes 2 sec, time to seal a bottle take 3 sec. Neglect all other times used for transferring the bottle from one unit to another.

xii.           Initially, different types of bottles will be fed into the packaging and sealing units from the unfinished tray.

xiii.         Bottles will be fed into the packaging unit from the unfinished tray in an alternative manner (if current input is B1 next input will be B2). Similar will be the case for the sealing unit.

xiv.         The input to the packaging unit from the B1 and B2 tray is alternative in nature. Initially, the priority of B1 is higher.

 

Write a java program which will generate the status of the bottles at a particular time.

If synchronization is required, use a synchronization technique different from the one you used in Problem 1. 

 

Sample Input/Output: 

Input: <No. of bottle type B1, No. of bottle type B2, Time duration for observation (in sec.)           Eg. 50, 50, 10 Output:  

Bottle Type 
Status 
Count 
B1 
Packaged 

B1 
Sealed 

B1 
In Godown 

B2 
Packaged 

B2 
Sealed 

B2 
In Godown 

 

Write a brief report on the following:

•       Discuss the importance of concurrent programming here.

•       Using code snippets describe how you used the concurrency and synchronization in your program.

•       How would the program be affected if synchronization is not used? Discuss

 

   

       Problem 3: Automatic Traffic Light System  
To assure the road safety in the campus, the IIT Guwahati administration has decided to install an automatic traffic light system in the T junction near old SAC.

 

A) Write a program in java to simulate the system considering the following:

i.           There are three traffic lights T1,T2 and T3   

ii.         T1 is for vehicles moving from South to East; T2 is for vehicles moving from West to

South; T3 is for vehicles moving from East to West iii.         Vehicles moving from South to West, East to South, and West to East can always move freely without any signal

iv.            If any of the traffic light is green, the other two must be red (eg. if T1 is green, T2 and T3 must be red)  

v.              Each traffic light turns green for 60 seconds only and one vehicle takes 6 seconds to pass

vi.            The traffic lights gets their turn in round robin manner

vii.           User gives the input as (source direction, destination direction) for example (North, South). The system automatically assigns a number and the timestamp to the vehicle and process accordingly

viii.         The program finds out weather to pass a vehicle or keep it waiting (keep an option to show the status of the vehicles to the user at any instant of time)

If you think synchronization is needed for the program, use a synchronization technique other than the one/ones you used in Problem 1 and Problem 2. 

B) Using java Swing package to create the GUI to show the simulation of the traffic light system

Sample Input/Output 

Input: East to West

 

Output:  

Vehicle: 21   Wait

 

[For status] Output:  

 

Traffic Light
Status
Time
T1
Red
--
T2
Green
15
T3
Red
--
 

Vehicle
Source
Destination
Status
Remaining Time
21
E
W
Wait
45
25
W
S
Pass
--
27
S
W
Pass
--
23
E
W
Wait
51
19
S
E
Wait
105
 

Write a brief report on the following:

•       Do you think the concept of concurrency is applicable while implementing the program? If yes, why? Explain using code snippets

•       Did you use synchronization in the problem? If yes, explain with code snippets  

•       If instead of T-junction, it would have been a four way junction (i.e. another way towards old

SAC), will there be any change in the problem implementation? If yes, write the pseudocode  

More products