title: Echo class in Java
body: <p>Please help me with this HW assignment. I am supposed to modify the EchoNumber class which extends the Echo class to count the number of characters in every line in a text file in addition to displaying the text. Here is the Echo class:</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.*;
  
  public class Echo{
    String fileName; // external file name
    Scanner scan; // Scanner object for reading from external file
  
    public Echo(String f) throws IOException
    {
      fileName = f;
      scan = new Scanner(new FileReader(fileName));
    }
  
    // reads lines, hands each to processLine
    public void readLines(){
      while(scan.hasNext()){
        processLine(scan.nextLine());
      }
      scan.close();
    }
  
    // does the real processing work
    public void processLine(String line){
      System.out.println(line);
    } 
  }
  </code></pre>
  
  <p>Here is the EchoNumber class, notice where it says "Your code goes here":</p>
  
  <pre><code>import java.io.*;
  
  public class EchoNumber extends Echo
  {
  
    // the current line number
    private int lineNumber;
  
    public EchoNumber (String datafile) throws IOException
    {
      super( datafile);
      lineNumber=1;
    }
  
    // Prints a line with a leading line number and a trailing line length
    // Overrides the processLine method in Echo class
    public void processLine(String line){
      /* your code goes here */
    }
  }
  </code></pre>
  
  <p>Here is the EchoTester class:</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  public class EchoTester
  {
  
    public static void main(String[] args)
    {
      // uses try/catch to handle IOExceptions in main
      try
      {
        String fileName;
        Scanner nameReader = new Scanner(System.in);
        System.out.println("Enter a file name");
        fileName = nameReader.nextLine();
        EchoNumber e = new EchoNumber(fileName);
        e.readLines();
      }
      catch(IOException e)
      {
        e.printStackTrace();
      }
    }
  }
  </code></pre>
  
  <p>And finally the .txt file:</p>
  
  <pre><code>The best things in life are free
  A stitch in time saves nine
  Still waters run deep
  He teaches ill who teaches all
  You can not take it with you when you die
  Better untaught than ill taught
  Do not cross your bridges before you come to them
  Soon learnt soon forgotten
  Even a worm will turn
  It was the last straw that broke the camels back
  The way to a mans heart is through his stomach
  If the stone fall upon the egg alas for the egg If the egg fall upon the stone alas for     the egg
  Where there is a will there is a way
  Marry in haste and repent at leisure
  One tongue is enough for a woman
  If you wish good advice consult an old man
  The best advice is found on the pillow
  All clouds bring not rain
  You can not tell a book by its cover
  No news is good news
  Bad news travels fast
  Live and let live
  Birds of a feather flock together
  Now is the time
  For all good men who actually have the time
  To come to the aid of the country in which they live
  </code></pre>
  
  <p>The output is supposed to be something like:</p>
  
  <p>1 The best things in life are free-32</p>
  
  <p>2 A stitch in time saves nine-27</p>
  
  <p>3 Still waters run deep-21</p>
  
  <p>4 He teaches ill who teaches all-30</p>
  
  <p>5 You can not take it with you when you die-41</p>
  
  <p>6 Better untaught than ill taught-31</p>
  
  <p>7 Do not cross your bridges before you come to them-49</p>
  
  <p>8 Soon learnt soon forgotten-26</p>
  
  <p>9 It was the last straw that broke the camels back-48</p>
  
  <p>Except without spaces between each line. For some reason it fuses into one paragraph if I did not separate each line.</p>