JMU
logoPIP.png
HeinousAlienLocator


Introduction

Purpose: HeinousAlienLocator is a class that can be used to locate an alien if it is on the JMU campus.

Existing Components
The sensor system consists of two classes:

Sensor ( Byte Code )

SensorDisplay ( Byte Code )

and uses the following image:

You will only use the Sensor class directly (the Sensor class uses the SensorDisplay class). Further, you will only use the int scan(int x, int y, int width) method in this class. This method is passed the square area to scan (x and y are the upper-left corner of the area and width is the width and height of the square). It returns -width if the alien is not in the square area and width if the alien is in the square area.

When running, the Sensor looks something like the following:

Sensor.png

The gray areas are those that did not contain the alien of interest, the purple lines are used to delineate the area that is currently being scanned, and the flashing purple square (not shown) indicates the area that is currently being scanned.

New Components
You must develop the following new components:
You must write a HeinousAlienLocator class with the following public methods:
import java.awt.Point;


public class HeinousAlienLocator
{
    public HeinousAlienLocator(Sensor sensor)
    {
       // Your code here
    }
    


    public Point search(int x, int y, int width)
    {
       // Your code here
    }
    

   // Your code here
}
  

The search() method will be called by the HALDriver to initiate a search in the area defined by the parameters x, y, and width. Hence, the search() method is responsible for doing the work of locating the alien (thought it can, of course, call other methods). This method must return null if the alien is not in the area of interest and must return a Point object with the coordinates of the cell containing the alien if it is in the area of interest.

Your implementation must satisfy the Software Requirements Specification (SRS).

You must use the following driver to test your code (and you must not change it):

HALDriver ( Source Code )

Command-line argument 0 contains the name of the alien to search for (and is required), command-line argument 1 contains the number of milliseconds to devote to each scan (and is optional).

Note that the driver does three main things: constructs a Sensor object, constructs a HeinousAlienLocator object (passing the constructor the Sensor to use), and calls the HeinousAlienLocator object's search() method passing it the square that contains the entire campus.

For debugging purposes:

  • The scan time controls the speed of the visualization. Longer scan times will make it easier for you to see what your HeinousAlienLocator is doing.
  • You can disable the Scanner window with a scan time of 0.
  • The following aliens are known to frequent the JMU campus: Beeblebrox, Chewbacca, Fourarms, Kang, Neelix, Omastar, and Stitch. You can also test the system using UL, LL, UR and LR (fake aliens that are at the upper-left, lower-left, upper-right, and lower-right corners).
Help Getting Started:
Approach: This assignment will be much easier to complete if your algorithm is recursive. Indeed, it is possible to write a recursive algorithm that contains fewer than 10 lines (though your algorithm may have more than that).
Allocating Time: Almost all of your time on this assignment should be spent thinking; very little time should be spent typing/compiling/etc... It is very unlikely that you will discover an algorithm that works through trial and error (i.e., try something, compile, test, make a change, repeat).
Writing a Recursive Algorithm: Remember that there are two parts of a recursive algorithm:
  1. The part of the algorithm that handles the "easy" (or "base") case.
  2. The part of the algorithm that moves "difficult" cases toward the "easy" case (i.e., the refinement part of the algorithm).

The first thing to think about is how to define the "easy/base" case. To do so, suppose your HeinousAlienLocator calls the scan() method in the Sensor class. When is its job really easy? (Hint: There may be more than one easy case.)

The second thing to think about is what you need to do to refine other cases (i.e., take hard cases and move them closer to the easy case).

Copyright 2011