JMU
logoPIP.png
Programming Assignment 5


1 Overview: People in Purple is a super-secret equal-opportunity organization that monitors aliens (e.g., Arquillian's, Ballchinians, Kylothians, Remoolians, Ewoks, Hutts, Wookies, Daleks, Oods, Raxacoricofallapatorian, Sontarans Druidians, and Mawgs) on the JMU campus. They have a sensor that can determine if a particular alien is in a particular square grid. They have asked you to create a HeinousAlienLocator class that uses this sensor to determine if a particular alien is anywhere on campus and, if so, where it is.
2 Design Documents: The following design documents exist:

Your submission must be consistent with these documents.

3 Getting Started: Before you start thinking about building a full-fledged HeinousAlienLocator, you might want to play around a little bit. For example, here's a HeinousAlienLocator that scans the whole area and then scans some cells around I81. (Note: As it turns out, this algorithm will find Omastar.)
import java.awt.Point;

public class HeinousAlienLocator
{
    private Sensor      sensor;
    

    public HeinousAlienLocator(Sensor sensor)
    {
       this.sensor = sensor;       
    }
    

    public Point search(int x, int y, int width)
    {
       int      resultOfScan;       
       Point    resultOfSearch;
       
       
       resultOfSearch = null;                

       // Check the whole area
       resultOfScan   = sensor.scan(x, y, width);

       if (resultOfScan < 0) // The alien isn't in the area
       {
          resultOfSearch = null;
       }
       else // The alien is in the area so let's search some more
       {
          // Try some cells around I81
          for (int xx=300; xx<340; xx++)
          {
             resultOfScan = sensor.scan(xx, 323, 1);
             if (resultOfScan == 1)
             {
                resultOfSearch = new Point(xx, 323);
                break;
             }
          }
       }
       
       return resultOfSearch;
    }
}
   
Going Further


Copyright 2011