©2006 Felleisen, Proulx, et. al.

9  Mutating a Structure Raising and Catching Exceptions Traversals Javadocs

Goals

In the first part of this lab you will learn to design methods that change the contents of a compound object.

In the second part of the lab you will start using the type parameters (Java generics).

The third part introduces a several new ideas:

9.1  Designing State Change

For this part download the files in Lab9-Part1-Student.zip. The folder contains the files Balloon.java, TopThree.java, and Examples.java.

Starting with partially defined classes and examples will give you the opportunity to focus on the new material and eliminate typing in what you already know. However, make sure you understand how the class is defined, what does the data represent, and how the examples were constructed.

Create a new Project Lab9-Part1 and import into it the files files Balloon.java, TopThree.java, and Examples.java. Also import the TestHarness.jar files and jpt.jar from the previous lab.

The class Balloon represents a balloon at some location, with some radius and color. The method inflate allows us to change the radius of the Balloon.

The class TopThree represents three balloons. The goal is to have the three balloons ordered, so that the best one is the value of the field one, the second best is the value of the field two, and the third best it the value of the field three.

The ordering is determined by the behavior of the Comparator instance that is a field of the TopThree object.

9.2  Java Generics: Using Type parameters

For this part download the files in Lab9-Part2-Student.zip. The folder contains the files Balloon.java, ImageFile.java, ISelect.java, IChange.java, TopThree.java, and Examples.java.

Create a new Project Lab9-Part2 and import into it the files Balloon.java, ImageFile.java, ISelect.java, IChange.java, TopThree.java, and Examples.java. Again, import the test harness files and jpt.jar.

Read briefly all files and compare them to those used in Part 1. Add to the class TopThree the method reorder and change the constructor as you did in the Part 1.

Notice that we have replaced the methods that change the state of one object (either a Balloon or a ImageFile) by a method change and have the classes implement a common IChange interface.

9.3  Documentation, Traversals, Exceptions, Java Libraries

For this part download the files in Lab9-Part3-Student.zip. The folder contains the files Balloon.java, ImageFile.java, ISelect.java, IChange.java, TopThree.java, and Examples.java. In addition, there are several new files: The file Traversal.java defines the Traversal interface, the files AList.java, MTList.java, and ConsList.java that define a generic cons-list that implements the Traversal interface. The file IllegalUseOfTraversal.java illustrates the definition of an Exception class. Finally, the Algorithms.java file shows an implementation of an algorithm that consumes data generated by a Traversal iterator.

Create a new Project Lab9-Part3 and import into it all files from the zip file. Again, import the test harness files and jpt.jar.

Generating Documentation

Defining and Handling Exceptions

ArrayList and Java Libraries

Last modified: Friday, November 3rd, 2006 2:34:09am