logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

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

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. 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. The LineItem class will represent an individual

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

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

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

expert
Atharva PatilComputer science

507 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

509 Answers

Hire Me
expert
AyooluwaEducation

597 Answers

Hire Me
expert
RIZWANAMathematics

620 Answers

Hire Me

Get Free Quote!

379 Experts Online