Question: Exercise 2 [ 6 0 marks ] This exercise follows on from the previous. It concerns writing a program called MarketPlace . java that creates
Exercise marks
This exercise follows on from the previous. It concerns writing a program called
MarketPlacejava that creates a collection of Seller objects from a data file, and then
searching for and printing those that sell a product meeting the user's criteria for quantity and price.
The program will ask the user to enter the name of a "Comma Separated Values" CSV file
containing seller data. The first line of the file will consist of an integer N that represents the
number of sellers.
Each subsequent line will consist of the comma separated values of the attributes for a single seller.
For example,
KP Kwik Pic, Bolton Hill, Cauliflower, R
FM Farmers Market, Imizamo Yethu, Lettuce, R
BAL BuyAlot, Salt River, Concrete Block, R
NA NotAllot, Claremont, Hot Air, R
STWD ShopTillWeDrop, Cape Town CBD Lettuce, R
SSeven, Milnerton, Fish fillets, R
MM Mega Mart, Phillipi, Lettuce, R
GNG GetnGo, Rantanga Junction, Lettuce, R
The program will:
Read in and create an array of Seller objects from the data.
It will then ask the user to enter the name of a product, the quantity required, and the
maximum that they are willing to pay per unit.
It will then search the array, printing out details of those sellers that can meet the
requirements.
If there are no matches, then it will print None found.
You will need to use Java arrays and know how to use Scanner objects to process input from file.
Explanations may be found in the appendices at the end of this document.
Version ::
Page of
Sample IO The input from the user is shown in bold font do not program this:
Enter the name of a "Comma Separated Values" CSV file:
sellers.csv
Enter the name of a product:
Lettuce
Enter the number of units required:
Enter the maximum unit price:
R
FM : Farmerss Market in Imizamo Yethu, has Lettuce for R each.
STWD : ShopTillWeDrop in Cape Town CBD has Lettuce for R each.
Sample IO The input from the user is shown in bold font do not program this:
Enter the name of a "Comma Separated Values" CSV file: mydata.csv
The file contains no seller data.
Sample IO The input from the user is shown in bold font do not program this:
Enter the name of a "Comma Separated Values" CSV file:
shops.csv
Enter the name of a product:
Fire lighters
Enter the number of units required:
Enter the maximum unit price:
R
None found.private MarketPlace Create an instance of Seller with attributes ID name, location, product,private static Seller makeSellerfinal String data scanner.useDelimiterss; return seller; Read the contents of CSV file into an array.private static Seller parseFilefinal String fileName throws FileNotFoundException Seller sellers null; sellers new SellerIntegerparseIntinFilenextLinetrim; sellersindex makeSellerinFilenextLine; return sellers;public static void mainfinal String args throws FileNotFoundException System.out.printlnEnter the name of a Comma Separated ValuesCSV file:"; Your Code here
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
