Question: Exercise 2 [ 6 0 marks ] This exercise follows on from the previous. It concerns writing a program called MarketPlace . java that creates

Exercise 2[60 marks]
This exercise follows on from the previous. It concerns writing a program called
MarketPlace.java 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,
8
KP01, Kwik Pic, Bolton Hill, Cauliflower, R10.00,120
FM01, Farmers Market, Imizamo Yethu, Lettuce, R11.25,132
BAL01, Buy-A-lot, Salt River, Concrete Block, R3,900
NA01, NotAllot, Claremont, Hot Air, R99.99,0
STWD01, ShopTillWeDrop, Cape Town CBD, Lettuce, R10.00,100
24S01,24-Seven, Milnerton, Fish fillets, R21.50,132
MM01, Mega Mart, Phillipi, Lettuce, R13.00,132
GNG01, GetnGo, Rantanga Junction, Lettuce, R9.00,50
The program will:
1. Read in and create an array of Seller objects from the data.
2. 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.
3. 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 2024/07/2910:13:19
Page 3 of 7
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:
87
Enter the maximum unit price:
R12.00
FM01 : Farmerss Market in Imizamo Yethu, has 132 Lettuce for R11.25 each.
STWD01 : ShopTillWeDrop in Cape Town CBD has 110 Lettuce for R10.00 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:
10
Enter the maximum unit price:
R5.00
None found.private MarketPlace(){}// Create an instance of Seller with attributes ID, name, location, product,private static Seller makeSeller(final String data){ scanner.useDelimiter("\\s*,\\s*"); return seller;// Read the contents of CSV file into an array.private static Seller[] parseFile(final String fileName) throws FileNotFoundException { Seller[] sellers = null; sellers = new Seller[Integer.parseInt(inFile.nextLine().trim())]; sellers[index]= makeSeller(inFile.nextLine()); } return sellers;public static void main(final String[] args) throws FileNotFoundException { System.out.println("Enter the name of a \"Comma Separated Values\"(CSV) file:"); // Your Code here}
Exercise 2 [ 6 0 marks ] This exercise follows on

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!