Experiments in Java


Problems for Session X2: Vectors

Problem X2-A: Default size of vectors

Java purports to be platform independent. While it is certainly clear that some aspects of Java, such as the number of bits used for primitive types, are tightly specified and therefore precisely uniform across implementations, others may be less well specified. Look through whatever Java documentation you can find and determine if there is a specified default size and growth rate for Java vectors.

Problem X2-B: Implement sets

When writing programs, it is often useful to have a Set class. Such Sets are a lot like mathematical sets: you can add elements, remove elements, and test for containment. However, a set contains an most one copy of any element. Using vectors, implement an IntegerSet class that permits programmers to work with sets of integers. Your class should support the following methods:

Problem X2-C: Other vector capabilities

We have covered only some of the methods provided by java.util.Vector. Find documentation for this class and identify its other methods. For each method, suggest a programming problem that might require the method.

Problem X2-D: Implementing vectors

Suppose that there were no java.util.Vector class. You might find it advisable to implement your own. Implement a Vector class that supports addElement, elementAt, setElementAt, and removeElementAt. You need not worry about what to do when there are errors, although you can print an error message if you'd like.

Problem X2-E: Printing arrays

Java permits you to print vectors through use of the toString method. Try to determine if there is a way to print out arrays. If not, write a method that one might use to print out arrays. This is a difficult problem, as there are many different kinds of arrays; you may want to limit yourself to printing out arrays of integers.

Problem X2-F: A grading program

Use the ClassList and Student classes to provide a more comprehensive grading program. Your program should allow the instructor to

It is likely that you will need to add new fields to the Student class (such as separate fields for each component of the grade) and add methods to the ClassList and Student classes.


Copyright (c) 1998 Samuel A. Rebelsky. All rights reserved.

Source text last modified Tue Oct 26 12:07:03 1999.

This page generated on Tue Oct 26 15:37:12 1999 by Siteweaver.

Contact our webmaster at rebelsky@math.grin.edu