APS101: Assignment 2

Purpose

This assignment will give you practice writing if-statements, loops, and manipulating Strings, as well as working with ASCII code and binary representation. You will also develop your own JUnit TestCase classes.

If you notice parts that are unclear, then please post a message to the discussion board. Any major changes/clarifications will be posted to the A2 FAQ page.

Introduction

You will write two classes (Passport and Spy), and two test classes (PassportTester and SpyTester). The Passport class is a simplified representation of a real passport. It contains information about which countries the owner of the passport has visited, and for how long. The Spy class contains methods to encrypt and decrypt messages, as well as information about the secret code names of Spies that are already operating.

You should find the following useful:

Here are some examples of input and output that is produced by methods in the Passport class.

Here are some examples of input and output that is produced by methods in the Spy class.

Test Classes

How do you know whether the Passport and Spy classes that you write are correct or not? The only way you can be sure is if you test them. Every time you write a method for your Passport and Spy classes you should also write a couple of tests for it, and run your collection of tests frequently to make sure that everything works correctly.

Write two JUnit TestCase classes: PassportTester and SpyTester. Make sure that your test classes adhere to the following principles:

Helper Methods

You are strongly encouraged to add "helper" methods. Whenever you find yourself repeating code (cutting and pasting, for example), you should think strongly about whether that code should be in a helper method. We will be looking for this when we mark. As an example and a  hint,  you should write a helper method in the Spy class to add new code numbers whenever a new Spy is created (i.e., whenever a constructor method is called).

We'll be looking for places where you should call existing methods (methods that are specified in the assignment description), and we'll be looking to see if you added new helper methods.

Important Note: Any helper methods that you add should be private. This is because they are intended for use only within the class (not for use by other classes). It's not required to write testers for these private helper methods.

Class Passport

Click on the link to see a description of this class in an API-style format.

Class Spy

Click on the link to see a description of this class in an API-style format.

Restrictions

You may not use arrays, Vectors, ArrayLists, or any other sort of list. Doing so will result in a significant deduction.

Marking

For this assignment, you will be marked on several things:



Also, make sure that you read the Assignment rules page for some general rules and guidelines -- there are more hints there about commenting and style.

What to Hand In

The course website describes how you hand in your assignment. This section tells you what to hand in:

Remember that spelling, including case, count in Java: your files must be named exactly as above.

NOTE: Other than the signoff statement, only hand in the files that end with the .java suffix. Be careful about this, because in the same place as your .java files you may also have files with the extension .class (that is, they end with the .class suffix), but otherwise have the same name. Two particular pitfalls:

Since .class files cannot be read by TAs or run with our testing programs, submitting the wrong files might cause you to fail the assignment. Every year, a half-dozen students submit the wrong file; we simply cannot do anything to fix this mistake.