import java.awt.Point;


public class HALDriver
{
    
    

    public static void main(String[] args)
    {
       HeinousAlienLocator     hal;       
       int                     scanTime;       
       Point                   result;       
       Sensor                  sensor;

       if ((args == null) || (args.length == 0))
       {
          System.out.println("You didn't tell me what alien to locate.");
          System.out.println("Please use the following syntax: ");
          System.out.println("     HALDriver alien [scantime]");
          System.out.println("where the scantime is in milliseconds.");
       }
       else
       {
          scanTime = 0;
          
          if (args.length > 1)
          {
             try
             {
                scanTime = Integer.parseInt(args[1]);                
             }
             catch (NumberFormatException nfe)
             {
                scanTime = 1000; // 1000 milliseconds (i.e., 1 second)
             }
          }
          
          sensor = new Sensor(args[0], scanTime);

          hal    = new HeinousAlienLocator(sensor);
          result = hal.search(0, 0, 512);

          System.out.print("Alien " + args[0] + " ");             
          if (result == null) 
             System.out.println("not located.");
          else                
             System.out.println("located at " + result.x + "," + result.y);
          System.out.println("");          
          System.out.println(sensor.checkSystem());             
       }
    }
    
}
