Programming Problem1- Merchandise sale for Alcheringa 2020 Solved

35.00 $

Category:

Description

Rate this product

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.

  1. The merchandise includes T shirts (of sizes S, M and L) and caps.
  2. A student can order only one item (either T shirt or cap) in a single order, but in any quantity.
  • To simulate multiple orders at the same time, consider taking input in batch and process them together.
  1. Use the concept of concurrency and multithreading to process the orders of the batch concurrently.
  2. Display the inventory list to the user before the order.
  3. An order is successful if sufficient quantity of the item is available, otherwise it is failed.
  • Use synchronization to avoid inconsistency in the inventory data.
  • 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

  • S 5
  • C 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:

  1. The packaging unit wraps a plastic cover to the bottle and the sealing unit seals the bottle with a cap
  2. Both the above units take the bottles from the unfinished tray (tray containing bottles which are neither packaged nor sealed)
  • 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
  1. 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.
  2. The packaging unit identifies and chooses appropriate package for the bottle. This unit can pack one bottle at a time.
  3. 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.
  • 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.
  • The priority of the trays containing bottles is higher than that of the unfinished tray.
  1. The number of bottles processed in each unit and those in the godown is stored in the database.
  2. The program should be written in such a way that the packaging and sealing units should incur minimum idle time.
  3. 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.
  • Initially, different types of bottles will be fed into the packaging and sealing units from the unfinished tray.
  • 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.
  • 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 2
B1 Sealed 1
B1 In Godown 1
B2 Packaged 3
B2 Sealed 2
B2 In Godown 2

 

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.

  1. A) Write a program in java to simulate the system considering the following:
  1. There are three traffic lights T1,T2 and T3
  2. 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

  1. 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)
  2. Each traffic light turns green for 60 seconds only and one vehicle takes 6 seconds to pass
  3. The traffic lights gets their turn in round robin manner
  • 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
  • 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.

  1. 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

  • Assignment-1-Concurrent-Programming-Java-wowagb.zip