CSC108H Winter 2000 Midterm
University of Toronto -- Department of Computer Science
CSC 108H - Winter 2000
Midterm Test  (A.L. Hunter's section)

Aids allowed: Textbook and API reference.
Length: 50 minutes

First Name: ___________________________    Last Name: ___________________________

Student ID: ___________________________    Tutor:        ___________________________

Your Mark:   1. _______ / 10     2. _______ / 10      3. _______ / 5      Total _______ / 25

1. [10 marks]
Complete the Java program begun below. It is intended to read one line of input and print it out again after substituting each occurence of the letter 'e' (lower case only) with an A, then a B, then a C, then a D, etc. You can assume that the input line has no more than 26 occurences of the letter 'e'.

Here is an example of input and the corresponding output:

  Input:     Eva. Please, there will be no noise!
  Output:   Eva. PlAasB, thCrD will bE no noisF!

public class Replace {
    public static void main (String[] args) throws IOException {
        BufferedReader in = new BufferedReader (new
			                      InputStreamReader (;
        // You write the rest.

2. [10 marks]
(a) Write a class "Cat" to describe cats that a pet store might be selling. Assume that the characteristics of cats that we wish to model are as follows:
  • the price (an amount such as 24.99)
  • the colour (a string such as "black").
  • the age of the cat in years (rounded up to the closest whole number;
            for example, a 3 month old cat would have an age of 1.)
  • All these characteristics should be set in the constructor, and "get" methods should be provided for each of them. In addition, you must make a 'toString' method that returns a string representing all of the information you've stored for the cat. You must choose your own method names (except for 'toString'), parameter lists, and return types.


    (b) Fill in the main method below with the statements to do these two tasks:

    i) Create a Cat object that is 3 years old, is orange, and has a price of $15.99.
    ii) Use the 'toString' method to display all information about the Cat object that you have created in step (i).
    public class PetStore {
        public static void main (String[] args) {
            // You write the rest.

    3. [5 marks]
    Here is a Java program, which compiles and runs without error messages. Write the output from the program in the space below it.

    class Teacher {
        private String name;    // Teacher's name
        private int    size;    // Size of class
        public Teacher (int theSize, String theName) {
            size = theSize;
            name = theName;
        public int getSize () {
            return size;
        public void compare (Teacher theTeacher) {
            if (theTeacher.size > 16)
                System.out.println ("You have a lot of students.");
            else if (size < 17)
                System.out.println ("I don't have many students.");
            else if (theTeacher.size < size)
                System.out.println ("You have more than me.");
                System.out.println ("I have less than you.");
        public void increment (int num) {
            size = num + 1;
            System.out.println ("Incremented to " + num);
    public class School {
        public static void main(String args[]) {
            Teacher one = new Teacher (18, "Sue");
            Teacher two = new Teacher (16, "Ed");
            int number = 3;
            one.increment (number);
            System.out.println (number);
            two = one;
            System.out.println (two.getSize());

    Write the output of this program here: