Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Engineering
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY