logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Bharat BhushanData mining
(5/5)

850 Answers

Hire Me
expert
Shilpi BhatnagarComputer science
(5/5)

826 Answers

Hire Me
expert
Woodrow BinionAccounting
(5/5)

996 Answers

Hire Me
expert
Maurice DugganNursing
(5/5)

927 Answers

Hire Me
Java Programming

Suppose you have decided to build your own online selling platform known as Amazing.com you have multiple sellers and buyers registered

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Problem

Suppose you have decided to build your own online selling platform known as Amazing.com. You have multiple sellers and buyers registered with Amazing.com. It has open access for both buyers and sellers. The sellers add the items to the catalog and once the buyers make a purchase from the catalog, the corresponding item is removed from the catalog. For the sake of simplicity, you may assume all the items are of a single type such as books or shoes. You listed some sellers as “preferred” sellers who have donated you some money. The preferred sellers have been given a priority order based on the amount they have donated you. When buyers make a purchase, they would always be delivered an item listed by a seller who is higher in the priority order. For example assume sellers s1, s2, and s3 have listed their books in the catalog. Also assume the priority order as s1 > s2 > s3 (s1 is most preferred). Now buyers have to first purchase all the items listed by s1 before making a purchase from other sellers. Further, consider a situation where a buyer is buying from s2 after all the items listed by s1 exhausted. In the meantime s1 again adds some items to the catalog. Once the current purchase from s2 completes, the next buyer must buy the item(s) listed by s1 before buying from any other seller. You may assume that the priorities are unique (no duplicates) and non-negative. In the starter code, the priorities are given as simple integers. Assume the lower number to be of higher priority. Being a student you’re on a budget and can’t afford expensive infrastructure. As a result, you have very limited space for the catalog. At any time at most N items can be stored in the catalog. If the catalog is already full, then the sellers need to wait for some buyers to buy items before they can add their product to the catalog. Also, if the catalog is empty, then the buyers need to wait until a seller adds their items to the catalog. Your task is to implement the Seller and Buyer classes using Java Threads.

 

Hint

You can model this question as to the classical Producer-Consumer problem. The sellers are the producers who produce items to the shared catalog and the buyers are the consumers who consume items from the catalog. As you can guess, since the buyers always buy from the preferred sellers, the catalog data-structure should be implemented using a Priority Queue. For the design of the system, each of the sellers takes an item from the shared queue called inventory and put it in the catalog. The buyers get (remove the item with the highest priority) items from the catalog. As we are using multiple buyer and seller threads all the operations have to be thread-safe (i.e., properly synchronized using concurrency primitives such as lock and conditions). Remember the thread-safe operation always happens on the shared resources. There are two shared resources in this design, the inventory list (shared between multiple producers) and the catalog priority queue

 

(shared between producers and consumers). Any operation on these data structures should be properly synchronized.

 

Starter Code

Download the Assignment2.tar.gz and extract it using the following command,

  tar -xvf Assignment2.tar.gz 

Inside the extracted Assignment2 folder you would find the Bases.java file which describes the abstract base classes and the interfaces that you would be implementing.

You are not supposed to change anything in the Bases.java and the Item.java files. Read the comments in the files to understand which parts you need to implement. You need to complete the implementations of the Node, Queue, PriorityQueue, Buyer, and Seller classes. The signa- tures and partial implementation for these classes are given to you. After you have implemented these classes, complete the Assignment2Driver class. Please go over the starter code thoroughly and make sure you understand the design. The parts that you need to complete are marked as TODO. You don’t need to alter any other part of the starter code.

Compilation and Testing

You can use the makefile for compilation and running the code. To compile your code, use

  make compile

To run the code, use

  make run

To clean the class files, use

  make clean

There is a sample test case given to you inside the tests/input.txt file. The tests/sample out.txt contains the expected output. You can also use the python script to check the correctness of your file. Run the runtest.py file, and you would see whether your implementation passes the given test case or not.

  python3 runtest.py

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme