University of Toronto - Fall 2000
Department of Computer Science

Assignment 1

Due: Tuesday September 26, 5:30 pm

At many universities students pay for their printing or photocopying using a copy card. The student purchases credits which are recorded electronically on the card. Then, each time a page is printed the card is charged for that page. The student can also ask the printer or copy machine to show how many unused pages are still on the card.

The java class PrinterCard models the behaviour of one of these printer cards. Download this class and read it. You will also need to download AssignmentOne.java which contains the shell of a main method for your assignment.

Part One

  1. Create a CodeWarrior project named AssignmentOne which contains both the AssignmentOne class and the PrinterCard class.
  2. Notice that the body of the main method in AssignmentOne.java contains only comment statements divided into Part One and Part Two. After each comment in Part One, add a single java statement as directed by the comment.
  3. Now after each of your added statements, add another statement or statements that report the number of page credits left on the relevant printer card. Report this in a sentence of exactly the form:
    You have x pages remaining.
    Except for x which will be replaced by an integer, you must print precisely these words including the capital Y, the period at the end of the sentence and the spacing: one space before the number, and one space after. In addition to looking at your program, we will be marking your output automatically and any output that isn't exactly as specified will receive a zero. You must use calls to getBalance() to complete this step in the assignment.
For Part One of the assignment you must not make any changes to PrinterCard.java

Part Two

  1. It could get very tedious to deduct 100 pages of printing from a printer card if this meant that print() had to be called 100 times. To improve the interface of the PrinterCard class, add another public method called printMultiple which has a single integer parameter representing the number of pages to print. Complete the body of this method and be sure to give it a method comment. Notice that print() doesn't check if the card actually has any available credit. It goes ahead and prints and deducts the page even if that sets the credit to a negative value. printMultiple should have the same behaviour. Later in the course we will learn how we could do better. Don't change anything else about the PrinterCard class.
  2. After each comment in Part Two of the main method in class AssignmentOne, add a single Java statement as directed by the comment, together with the necessary statements to print the balance of the card in the specified form (as explained in point 3 of Part One).
  3. Following the directions from the web-site, submit your corrected AssignmentOne.java and your improved PrinterCard.java for marking. Check the rules for submission carefully so you don't get a zero for a silly error (like submitting to the wrong directory, or with the wrong filename, etc.).