// ACMIOTest.java
// This test program illiustratese the ACMIO class
// It takes input from the file t.txt
class ACMIOTest
{
   public static void main(String[] args)
   {
      int j;
      ACMIO in = new ACMIO("t.txt");

      System.out.println("Follow through the input file t.txt!");
      System.out.println(
        "Read int, long, double, char, and String over several lines:");
      int i = in.intRead();
      long l =in.longRead();
      double d = in.doubleRead();
      char c = in.charRead();
      String s = in.stringRead();
      
      System.out.println(i + " " + l + " " + d + " " + c + " " + s);
      
      System.out.println(
        "Read int, long, double, char, and String, skip ends of lines:");
      i = in.intReadln();
      l = in.longReadln();
      d = in.doubleReadln();
      c = in.charReadln();
      s = in.stringReadln();
      
      System.out.println(i + " " + l + " " + d + " " + c + " " + s);    

      System.out.println("Four duplicate lines processed four ways:");
      System.out.println("All in one string:");
      System.out.println(in.getLine());

      System.out.println("Each token:");
      in.skipBlanks();
      while (!in.isEOLN()) {
        System.out.println(in.stringRead());
        in.skipBlanks();
      }
      in.skipLine(); // remove newline

      System.out.println("Each character:");
      while (!in.isEOLN()) 
        System.out.print(in.getChar());
      in.skipLine(); // remove newline
      System.out.println();
        
      System.out.println("read exactly 5 nonblank characters:");
      for (j = 0; j < 5; j++) 
        System.out.print(in.charRead());
      System.out.println();
      if (in.isEOF()) 
          System.out.println("Error! (says end-of-file)");
      else
          System.out.println("Not end-of-file");
      System.out.println(
           "Now skipping rest of last line, and testing for end-of-file:");
      in.skipLine();
      if (in.isEOF()) 
          System.out.println("IS end-of-file");
      else
          System.out.println("Error! (says NOT end-of-file)");
      System.out.println();
      System.out.println("Now testing format methods...");
        
      System.out.println(
        "Display 10.123456789 in field of width 8 and 0-10 digits precision:");
      d = 10.123456789;
      for (j = 0; j <= 10; j++) 
        System.out.println(ACMIO.format(d, 8, j));
      
      l = 579;
      s = "abc";
      c = 'z';
      System.out.println("Display "+ l + ", "  + c + ", and " + s + 
                             ", each with fieldwidth -5 to 5:");
      System.out.println("123456789012345 column markers");
      for (j = -5; j <= 5; j++) 
        System.out.println(ACMIO.format(l, j) + 
               ACMIO.format("" + c, j) + ACMIO.format(s, j));
      System.out.println("123456789012345 column markers again");
   }
}

