ITEC 1630 Object-Oriented Programming, Sections M, N, and O, Winter 2007

Assignment 1

Due date:

For all sections M, N, and O of ITEC 1630, the assignment must be submitted by Monday February 19 at 7pm.

To submit:

Prepare a single zip file containing all the source files (.java files, NOT .class files) and testsOutput.txt. Submit this file as an attachment to an email sent to: Put in the subject line your section (M, N, or O), name, student number, and the words "Assignment 1". Please make sure that your section is entered correctly. For example, if your name is Jane Doe, and your section is M, your subject line will be "M Jane Doe 999999999 Assignment 1". Your section must be in capital case. Your submission will not reach your TA and will therefore NOT be marked if a wrong section code is used in the subject line. It is highly recommended that you CC yourself on this email. You can email the program any time before the deadline. A printout of the source files and testsOutput.txt (no cover page is necessary but make sure the identification section at the beginning of is filled out and appears on top) is to be put in the drop box on the 3rd floor of TEL building before the deadline.


SuperPhoneCard Inc. sells phone cards for making cheap long distance calls around the world. In this assignment, you will write a (much simplified) Java program to manage their business.

SuperPhoneCard Inc. sells 3 types of phone cards: SuperNA10 cards, which cost $10 and are good only for calls in Canada and the USA, Global10 cards, which cost $10 and are good for overseas calls, and Global25 cards, which cost $25 and are also good for overseas calls. The per minute rates for each type of card and call zone are as follows:

SuperNA10 Global10 Global25
Canada $0.05 $0.07 $0.05
USA $0.10 $0.15 $0.10
Europe XXXXX $0.30 $0.20
Asia XXXXX $0.60 $0.40
Australia & NZ XXXXX $0.45 $0.30
Latin America XXXXX $0.45 $0.30
Africa XXXXX $0.60 $0.40

The initial balance on the cards and the weekly maintenance fee are indicated below:

SuperNA10 Global10 Global25
initial balance $10.00 $10.00 $25.00
weekly fee $0.50 $1.00 $1.00

Your main job in this assignement is to implement a hierarchy of classes to represent the different types of cards. At the top of the hierarchy, there is an abstract class PhoneCard with the following API:

There are also 3 classes, SuperNA10Card, Global10Card, and Global25Card that inherit from PhoneCard, and model the properties of the associated type of card as specified above, by defining the PhoneCard class's abstract methods. These classes should use the supplied class to represent call zones; it provides methods to convert strings representing the call zones to CallZone objects and to check if such strings are valid.

Once you have defined these classes, you should then complete the application that SuperPhoneCard Inc. will use to manage its business. This application is implemented by the SuperPhoneCardInc class, that reads and processes a number of commands from the standard input stream for processing cards and calls, outputing the results on the standard output stream. The commands are:

An incomplete definition for the SuperPhoneCardInc class is available here in You must fill out the missing parts of the definition, i.e. the code for handling the following commands: The SuperPhoneCardInc uses another class CardTable to manage a table of PhoneCards. An incomplete definition for the CardTable class is available here in You must also fill out the missing parts of the definition of CardTable, i.e. the public PhoneCard get(long no) method that returns the first phone card in the table whose number matches the argument, or null if there is no card with this number.

Make sure your code compiles and runs under the JDK available in the ITEC labs. Test your program with assertion checking enabled, e.g. with java -ea SuperPhoneCardInc (see Horstmann pp. 335-338 for details). Once you have implemented and thoroughly tested all of these classes, run your application on the test data file testsInput.txt and save your output in the file testsOutput.txt. Under Unix and Windows XP, you can do this by redirecting the standard input stream and standard output stream with the command:

java -ea SuperPhoneCardInc < testsInput.txt > testsOutput.txt

Then submit a zipped archive with all your source code files and testsOutput.txt by the deadline as specified above.