Question: Add at least one more test case you create for each method for the StringSorter class that is below using Java on VSC . Looking
Add at least one more test case you create for each method for the StringSorter class that is below using Java on VSC Looking for correctness in logic. Include detailed comments on the test cases. import java.io; for Reader and subclasses Writer and subclasses and IOException
import java.util.; for List, ArrayList, Iterator
public class StringSorter
ArrayList lines;
given that we don't really know how to deal with a readwrite error IOException
inside the functions, we'll let it pass through
public void readFromStreamReader r throws IOException
BufferedReader brnew BufferedReaderr;
linesnew ArrayList;
whiletrue
String inputbrreadLine;
ifinputnull
break;
lines.addinput;
public void writeToStreamWriter w throws IOException
PrintWriter pwnew PrintWriterw;
Iterator ilines.iterator;
whileihasNext
pwprintlnStringinext;
returns the index of the largest element in the list
static int findIdxBiggestList l int from, int to
String biggestString lget;
int idxBiggestfrom;
forint ifrom; ito; i
ifbiggestcompareTolgeti it is bigger than biggest
biggestStringlgeti;
idxBiggesti;
return idxBiggest;
assumes i i are in range
static void swapList l int i int i
Object tmplgeti;
lseti lgeti;
lseti tmp;
public void sort
forint ilines.size; i; i
int bigfindIdxBiggestlinesi;
swaplinesibig;
void sort
java.util.Collections.sortlines;
public void sortString inputFileName, String outputFileName throws IOException
Reader innew FileReaderinputFileName;
Writer outnew FileWriteroutputFileName;
StringSorter ssnew StringSorter;
ssreadFromStreamin;
sssort;
sswriteToStreamout;
inclose;
out.close;
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
