Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.io.*; public class EchoLongest extends Echo { // the current longest

ID: 3567391 • Letter: I

Question

import java.io.*;

public class EchoLongest extends Echo
{

  // the current longest line
  private String longest;

  public EchoLongest (String datafile) throws IOException
  {
    super(datafile);
    longest="";
  }

  // Sets the given line as the current longest if the line is
  // longer than the value stored in the longest.
  // Overrides the processLine method in Echo class
  public void processLine(String line){

  }

  public void printLongest(){
    System.out.print(longest);
  } //end method
} //end class|
Fill in process line

Explanation / Answer

public void processLine(String line){String result = "";
StringTokenizer st = new StringTokenizer(line," ");
while(st.hasMoreTokens())
{
result = result+st.nextToken();
}
wordCount=st.countTokens();//contains no. of words
System.out.println(result);
/* while(wordCount < line.length()){
wordCount += line.length();
}*/
}