Add at least one or more test case you create for each method for the StringSorter class. You do not need to compile and run the program. Your work is checked for correctness in logic. However, you must include detailed comments on the test cases. Submit the modified StringSorter.java.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

StringSorter.java is below:

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 read/write error (IOException)
   // inside the functions, we'll let it pass through
   public void readFromStream(Reader r) throws IOException
   {
       BufferedReader br=new BufferedReader(r);
       lines=new ArrayList();

       while(true) {
           String input=br.readLine();
           if(input==null)
               break;
           lines.add(input);
       }
   }

   public void writeToStream(Writer w) throws IOException {
       PrintWriter pw=new PrintWriter(w);
       Iterator i=lines.iterator();
       while(i.hasNext()) {
           pw.println((String)(i.next()));
       }

   }


   // returns the index of the largest element in the list
   static int findIdxBiggest(List l, int from, int to) {
       String biggest=(String) l.get(0);
       int idxBiggest=from;

       for(int i=from+1; i<=to; ++i) {
           if(biggest.compareTo(l.get(i))<0) {// it is bigger than biggest
               biggest=(String)l.get(i);
               idxBiggest=i;
           }
       }
       return idxBiggest;
   }

   // assumes i1, i2 are in range
   static void swap(List l, int i1, int i2) {
       Object tmp=l.get(i1);
       l.set(i1, l.get(i2));
       l.set(i2, tmp);
   }

   public void sort() {
       for(int i=lines.size()-1; i>0; --i) {
           int big=findIdxBiggest(lines,0,i);
           swap(lines,i,big);
       }
   }

   /*
   void sort() {
       java.util.Collections.sort(lines);
   }
   */

   public void sort(String inputFileName, String outputFileName) throws IOException{
           Reader in=new FileReader(inputFileName);
           Writer out=new FileWriter(outputFileName);

           StringSorter ss=new StringSorter();
           ss.readFromStream(in);
           ss.sort();
           ss.writeToStream(out);

           in.close();
           out.close();
   }

 

Add at least one or more test case you create for each method for the StringSorter class. You do not need to compile and run the program. Your work is checked for correctness in logic. However, you must include detailed comments on the test cases. Submit the modified StringSorter.java. 

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY