Assignment 8

Both parts of this assignment are to be done with pencil (or pen) on paper.

St. George students should hand their assignments to Danny Heap no later than 12 noon, April 12th, either in class or at SF2302A Monday, Tuesday, Wednesday 4--5pm, or Friday 11:30am until noon.

UTM students should hand in their assignments to the CSC 108 dropbox in the Computer Centre no later than noon April 12.

Part 1: Inheritance

The classes Person, Mother, Grandmother, and Aunt form a hierarchy: some are superclasses or subclasses of others. The main class, TestGenerations demonstrates these classes. You should print out TestGenerations, and add comments in pen as follows: Wherever you find a Java statement followed by:

// YOUR COMMENTS HERE
... you should decide whether the statement will cause an error or not You will also find some statements that have had appropriate comments already filled in. These are meant to guide you in the comments that you must fill in.

Part 2: running time

In each of the following problems you should describe an efficient algorithm that solves it (you can either describe it using precise English prose, or "Java-like" code). In each case, we designate the size of the problem to be solved as n (a non-negative integer). You should calculate the running time of your algorithm, expressing it as the number of operations (comparisons, assignment statements) in terms of n. If the problem requires that some initial values be stored in an array or Vector, you don't calculate the operations required for this storage.
  1. A program includes an array of n names. This array is a parameter for a method that shifts each of the names one location along in the array. The name that was at the end of the array is put in the first location. The method returns the altered array.
  2. A program includes an unsorted array of n integers. The array is passed as a parameter to a method that finds and prints the minimum value in the list.
  3. A program includes a Vector of n Objects. The Vector is a parameter for a method that prints the toString() value of the last Object in the Vector.
  4. A friend gives you a piece of paper with an unsorted list of n values and asks you to find the value that occurs the largest number of times.
  5. A method calculates the number of times a number, n, is divisible by 3 by repeatedly dividing by 3 until the result is 0.
  6. A program includes a Vector of n Objects. The Vector is passed as a parameter to a method that copies the Objects in the first half of the Vector to another Vector and returns the new Vector.

Marking

We may choose to mark all, or a subset, of the exercises in A8. For the best results, you should try to complete and hand in all of them.
Danny Heap
Last modified: Fri Apr 5 13:08:36 EST 2002