This assignment will give you practice writing if
-statements, loops, and manipulating String
s, 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.
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.
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:
Passport
and Spy
classes, your test
suites should have at least one test case that
tests that method.
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.
Click on the link to see a description of this class in an API-style format.
Click on the link to see a description of this class in an API-style format.
You may not use arrays, Vector
s,
ArrayList
s, or any other sort of list. Doing so
will result in a significant deduction.
For this assignment, you will be marked on several things:
Passport
and Spy
classes - commenting (all variables and methods are documented carefully) and naming (all variables and methods have
descriptive names, proper capitalization, and are appropriately public or private).
The course website describes how you hand in your assignment. This section tells you what to hand in:
Passport.java
PassportTester.java
Spy.java
SpyTester.java
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:
Microsoft operating systems often do not display file extensions unless they've been told to do so.
DrJava creates "backup files", which means that
you'll see filenames like "Passport.java~
".
Notice the ~
at the end. It indicates that the file is
a backup file, which happens to be an older version of your program.
Don't hand these in.
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.