CS 139 Algorithm Development
Lab14B: Aliens Among Us

Objectives:

Students will be able to:

In the last lab, you created a class of immutable objects called Color139. Today you will explore another immutable class and work with a class intending to be changed. That class contains some instance variables (attributes) as well as some class variables.

Background

Stallone    Frank the Pug - Men in Black        bugcup         Speilberg        
Some "aliens" from the movie.

The premise behind the "Men in Black" series of movies is that there are aliens on this earth who have sought a neutral planet for refuge from conflict elsewhere in the universe. Most are benign and in fact are helpful to society. But some go out of control. The "Men in Black" MIB keep track of the aliens and if warranted, "isolate" or "remove" them from the earth. (See the trailer at: http://www.imdb.com/title/tt0119654/)

A little known fact is that the Bridgeforth Stadium addition was partially funded through the MIB who built a secret detention center underneath the stadium turf. Aliens detained at the JMU location will be found at location: 38.435427 lat /-78.872942 long.

This application will enable them to "check in" new alien arrivals and track their whereabouts. Also, it is important that we know how many aliens we are currently tracking in order to determine manpower requirements. Aliens either eliminated or deported will be removed from the counts.

Materials:

Acknowledgment:  David Bernstein for the Location class.


Part 1 - Getting started

  1. Download a copy of MIB.java which contains the main method that creates some aliens and manipulates their data.
  2. Download a copy of Alien.java which contains a set of attributes of the aliens and the method headers (not stubs).
  3. Download a copy of Location.java which contains code for a set of locations.
  4. Finally, download a copy of worksheet.txt in which you must answer some questions as you go along and explore these classes.

Part 2 - Exploring Location.java

  1. Location.java is a class representing locations. Is this class mutable or immutable? Why do you identify it as such (what are the properties of the class)? Why is (mutable/immutable) appropriate for this class?
  2. The two instance variables represent latitude and longitude of a location. Why do we only have one constructor? Would there be any use for another constructor? Why or why not?
  3. What is the purpose of the two Location class constants? Why are they public? Is there any danger in making them public? Why or why not?

Part 3 - Building the Alien class

  1. The instance variables (attributes) in the Alien class are all listed with a privacy modifier of private. Why is this important? (explain why attributes should be made private)
  2. What is the purpose of the class variables in Alien? Why must they be static? What would happen if they were not static, for instance, if we added a new Alien object?
  3. Which of the methods that you see in Alien are mutator methods? Which are accessor methods? How many constructors do you see?
  4. Read carefully the description of each of the blank methods. In some cases you are altering class variables and instance variables; in others you are altering one or the other; and in some cases you are accessing data.
  5. Stub out each of the methods. (Provide a return value in keeping with the return type.) Get everything to compile before moving forward.
  6. Fill in the rest of the code. Use MIB to test your code.

Part 4 - Understanding Objects and Tracing

Using a model like we did in class on Monday and Wednesday, trace the execution of MIB on a blank piece of paper. You should show each instance variable as it is declared and show new values as they change. Think about how you will represent the class variables. Will you create one per object that you build or will you create only one set of class variables? Why or why not? (These do not need to be answered directly).

Handing in your work

Upload Alien.java and worksheet.txt to Blackboard, and turn in the model you created on paper. Make sure your name is on it. You will get 60 points for the successful program, 20 points for a completed thoughtful worksheet, and 20 points for the model. Note: you will be expected to do all of these things for the final exam.

Updated 11/28/2012 (nlh)