You have been asked to simulate an online computer tablet parts shop in a Java application. Customers select products from the online catalogue and proceed to the checkout. Records of stock levels are kept in a text file. Your prototype will contain a small text file for testing purposes. It should contain the following information (without the headings): Item price stock Battery 55 12 Screen Cover 40 210 SD Card 85 95 Charger 65 6 Cover 15 20

a. The stock file must be opened by a class named Stock, which reads the values into an appropriate array or list.

b. Each transaction is handled by a separate thread. The thread will check the stock levels of the requested item against the amount required by the customer. If there is enough of the item, the level of the stock should be decreased and the array updated. If there is not enough stock, the user must be given an appropriate error message.

c. Only one thread can access the Stock's array at a time to ensure levels are accurate. E.g. if one customer requests 8 batteries and another customer requests 4 at the same time (either request processed first) from a different transaction, the first customer should get the 8 batteries and the second customer should be given a message telling them that there is not enough stock.

d. The stock figures should never reach a minus figure. This will require synchronization between threads.

e. Write a class called Transaction that accepts an item description and a quantity in the constructor. The Transaction class should check stock and update the array once its thread is executed. Each transaction should take 2ms to complete. The current stock levels should be displayed in the console after each transaction.

f. Write a test class called TransactionTest that initialises a Stock object, creates 10 transactions and executes them at the same time. Be sure to include a scenario where two Transactions compete for a particular stock item. Write a second test class that generates and executes transactions with random item description and random quantity (between 1 and 10) until all stock levels have been depleted.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.