// TimeTest3.java
// Tests the equals method of class Time

import java.util.StringTokenizer;

public class TimeTest3  {
   public static void main(String[] args)
   {
      Time t1 = inputTime();
      while ( true )  {
         System.out.println("The time you just now entered will be "
                            + "compared to the next time you enter.");
         Time t2 = inputTime();
         System.out.print(t1 + " and " + t2);
         if ( t1.equals(t2) )
            System.out.print(" ARE ");
         else
            System.out.print(" are NOT ");
         System.out.println("equal.");
         t1 = t2;
      }  // while
   }  // class main

   public static Time inputTime()
   {
       try  {
          System.out.print("Enter a 24-hour time in "
                           + "HH:MM:SS or HH MM SS format " 
                           + "(or X to quit);>");
          String line = ConsoleInput.readLine();
          if ( line.equalsIgnoreCase("X") )
             System.exit(0);
          StringTokenizer st = new StringTokenizer(line, " :\t");
          int h = Integer.parseInt(st.nextToken());
          int m = Integer.parseInt(st.nextToken());
          int s = Integer.parseInt(st.nextToken());

          Time time = new Time(h, m, s);
          System.out.println("You entered " + time + ", or "
                             + time.to12HourString()
                             + ", " + time.getTotalSeconds()
                             + " seconds after midnight.");
          return time;
       } catch ( RuntimeException re )  {
           System.out.println("Not a valid time input.  Try again.");
           return inputTime();   // recursive call to this method itself
       }  // catch
   }  // method testTime(int, int, int)
}  // class TimeTest3