import becker.io.*;

public class Application
{
  private ThreeDecimal maxSoFar = DataFactory.makeThreeDecimal();
  public static final String FILE_IN = "input.txt";
  public static final String FILE_OUT = "output.txt";

  public Application()
  //pre: file FILE_IN is correctly formatted (at least one line, one number per line until EOF)
  //post: reads in from a file and writes to FILE_OUT with the largest number in the file
  {
    this.findMaxInFile();
    this.printMaxToFile();
  }


  private void findMaxInFile()
  //pre: file FILE_IN is properly formatted.
  //post: assigns maxSoFar a reference to a ThreeDecimal object with the largest value found in FILE_IN
  {
    TextInput in = new TextInput(FILE_IN);             //opens the file
    ThreeDecimal curr = DataFactory.makeThreeDecimal();//gets a new instance of type ThreeDecimal from the DataFactory
    curr.setValue(in.readDouble());                    //sets the current ThreeDecimal to the first number in the file
    this.maxSoFar.setValue(curr.getValue());           //sets the maximum found so far to the first number in the file
    in.readLine();                                     //advance to the next line

    while(!in.eofIsAvailable())                        //loop through the rest of the file
    {
      curr = DataFactory.makeThreeDecimal();           //makes a new current ThreeDecimal object (included for clarity)
      curr.setValue(in.readDouble());                  //sets the value of the curr to the next numer in the file

      ThreeDecimal newMax = this.maxSoFar.max(curr);   //finds the max between maxSoFar and the current double just read
      this.maxSoFar = newMax;                          //assigns the new max to maxSoFar
      in.readLine();                                   //move to the next line
    }
  }

  private void printMaxToFile()
  //pre: Max value has been found
  //post: the max number found in decimal form is printed to file FILE_OUT
  {
    TextOutput out = new TextOutput(FILE_OUT);
    out.println(maxSoFar.getValue());
    out.close();
  }

}