You are on page 1of 4

Comp 401 Assignment 6:

Collections
Date Assigned: Wed Sep 29, 2010

Completion Date: Fri Oct 8, 2010

Early Submission Date: Wed Oct 6, 2010


In this assignment, you will use arrays to create different variable-sized
collections. You will create fairly complex logical structures, with collection
embedded in other objects. In fact, the main challenge in this assignment is
to create such structures.

You will use ObjectEditor to display the elements of the collections. Thus, you
must follow ObejctEditor conventions for read methods of a variable-sized
collection. You do not need to do so for write methods. Moreover, while you
should use ObjectEditor to invoke methods to remove elements, you should
not use ObjectEditor to add elements to the collection. The reason is that
each of these collections consists of composite objects such as a shape and
ObjectEditor does not provide a convenient way to instantiate method
parameters that are composite objects. You can programmatically add
elements to connections in main and other methods of your class. Make
sure a collection is fully populated before you ask ObjectEditor to display it so
that you dont have to interactively add elements to it.

Besides collections, you will create other kinds of objects, which will
ultimately be associated with collections

In this and future assignments, some classes may be accidentally recognized


as implementations of atomic shapes. Some of the composite graphics
objects you will create may end up having graphics properties such as
Cartesian coordinates. If the names of the classes and interfaces of these
objects contain strings such as Point and Oval that denote atomic shapes,
these composite graphics objects will be treated by ObjectEditor as atomic
graphics objects . Thus, you might have to play around with the names of
classes and interfaces to get the correct display. When you study
annotations, you will see ways around this problem.

House with Path and Mailbox


Create a new class that adds a path to the class you created in the previous
assignment to represent a house with a mail box. The exact placement, size,
and nature of the path is up to you I have used a rectangle, as shown below.
Later, you will have to determine if an avatar is within a path. Therefore,
make it a graphics object that makes it easy to make this determination.

Candy
Create a graphics class representing a candy. It can be a simple oval, as
shown below, or an image or a complex graphics object that is more realistic.

Candy Container
Create a graphics class representing a candy container an object, such as
the one shown below, that can contain multiple candies. You can assume a
limit on the number of candies that can be put in a candy container.

Candy List
Create a similar class that represents a collection of candies. This collection
should also support two write methods: a single-parameter method that adds
a candy (specified by the argument of the method), and a parameterless
method that removes the last added candy from the collection. Like the
house list, the collection does not determine the geometry of the elements
(positions and sizes) each element of the collection does.

Candy Container with Candy List


Create a class that represents a candy container with a collection of candies
in it. This class should determine the positions of the candies to ensure that
(1) each candy is fully contained in the container, and (2) no candy is
completely hidden by other candies. The class should define a
parameterless method to add a candy to the candy list.

House List
Create a class that represents a collection of houses (with mailboxes and
paths). The collection should support two write methods: a single-parameter
method that adds a house (specified by the argument of the method), and a
parameterless method that removes the last added house from the
collection. The collection does not determine the geometry of the elements
(positions and sizes) each element of the collection does.

Token List
Define a class (and interface) to represent a collection of token-objects (which
were defined in the token assignment). For now, make the collection a
history. Later you might need to modify the collection to implement some
extra credit features.

Input String with Token History


Create a version of the stateful classes of assignment 4 (and 3). Like these
classes, the new class has two properties. One of these properties is the
independent editable property storing the scanned string. The second
property, however, is no longer a string property. Instead, it is a dependent
readonly property storing an instance of the token history class that contains
all the tokens in the scanned string (in the order these tokens were scanned).

Tester (Extra Credit)


Write a tester for the class implementing the candy container with candies
that checks that the two constraints given in its definition are actually met.

Main Class
Write a main class, using the conventions mentioned in earlier assignments,
to test all of the classes above. Execute this class to create console and
ObjectEditor windows demonstrating the correct behavior of these classes.

Extra Credit Summary


1. The tester.
2. Graphics classes representing candies, paths, and containers that look
more realistic than what I have created.

Constraints
As always, try and follow all style principles you have learned so far in
class, and use only the concepts seen in class so far, and specified in
earlier assignments. This means you cannot use the class Object in
the definition of your collection classes. You must carefully choose the
type of the element of each collection so that only legal objects in the
collection can be stored in it.

Questions to be answered
Answer the following questions:

1. The assignment requires you to create three separate classes to


display candies: a candy list, candy container, and a candy container
with candy list. Why not create just (a) one class: a candy container
with candy list, or (b) two classes, candy list and a candy container
with candy list? Illustrate your answers with examples, if possible.
2. Classify each collection class as a history, database, (transparent)
stack, or (transparent) queue.

Submission Instructions
Submit to blackboard your code together with screenshots of test cases and a
document identifying the extra credit features and containing the answer to
the questions

You might also like