Question: import java.io . BufferedReader; import java.io . FileReader; import java.io . IOException; public class Main { public static void main ( String [ ] args
import java.ioBufferedReader;
import java.ioFileReader;
import java.ioIOException;
public class Main
public static void mainString args
Market m new MarketMinnesota;
Market m new MarketMichigan;
Market m new MarketNorth Dakota", ;
System.out.printlnmcompareTom: mcompareTom;
System.out.printlnmcompareTom: mcompareTom
;
MarketSortedSet sort new MarketSortedSet;
String filePath askUserForFilePath;
try BufferedReader br new BufferedReadernew FileReaderfilePath
String line;
while line brreadLine null
String parts line.split;
int type Integer.parseIntparts;
String stringValue parts;
int intValue Integer.parseIntparts;
switch type
case :
int zip Integer.parseIntparts;
Zip itemA new ZipstringValue intValue, zip;
sort.insertitemA;
break;
case :
boolean TF Boolean.parseBooleanparts;
TF itemB new TFstringValue intValue, TF;
sort.insertitemB;
break;
case :
Market item new MarketstringValue intValue;
sort.insertitem;
break;
default:
System.out.printlnInvalid item type encountered: type;
System.out.printlnItems in sorted set:";
System.out.printlnsort;
testIndexOfsort;
testRemovesort;
testGrabsort;
testCategorySetsort;
catch IOException e
eprintStackTrace;
private static String askUserForFilePath
This method should ideally prompt the user for the file path
or accept it from commandline arguments.
return "spot.txt; For now, returning a fixed file path for testing
private static void testIndexOfMarketSortedSet set
System.out.printlnTesting indexOf method:";
Market item new MarketMinnesota;
int index set.indexOfitem;
if index
System.out.printlnItem found at index: index;
else
System.out.printlnItem not found.";
private static void testRemoveMarketSortedSet set
System.out.printlnTesting remove method:";
Market item new MarketMinnesota;
if setremoveitem
System.out.printlnItem removed successfully.";
else
System.out.printlnItem not found or could not be removed.";
System.out.printlnUpdated set:";
System.out.printlnset;
private static void testGrabMarketSortedSet set
System.out.printlnTesting grab method:";
Market item set.grab;
if item null
System.out.printlnItem at index : item;
else
System.out.printlnSet is empty or index out of bounds.";
private static void testCategorySetMarketSortedSet set
System.out.println
Testing categorySet method:";
System.out.printlnCategory Zip:;
MarketSortedSet category set.categorySet;
System.out.printlncategory;
System.out.printlnCategory TF:;
MarketSortedSet category set.categorySet;
System.out.printlncategory;
System.out.printlnCategory Items:;
MarketSortedSet category set.categorySet;
System.out.printlncategory;
Code can't read my txtfile. plz help
your driver should read the data from a text file where each line in
the input file represents one item and the line includes the following values separated by
tab: a number or to specify whether the line represents an ItemA, ItemB, or
Item object respectively, string value, integer value, and an integer value for
ItemA lines or boolean value for ItemB lines. Assume the input file is formatted correctly
and you do not have to check for lines that are not in the given format. This is an example
input file:
aaa
bbb true
ccc
aaa false
Create an input file of at least lines with at least lines for each item type
ItemItemAItemB Include some duplicate lines to test that the add method does not
add duplicate items.
Write code to ask the user for the path of the data file, read the file name, open the file
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
