CS242: Advanced Programming Concepts in JAVA

Fall 2008

Program 4

Due: 10:00 AM, Monday, 9/22/08

(a) A container class is a class that contains objects. Java has lots of container classes, but this assignment is to implement some simple container classes of your own design.

Class Bag is an abstract container class.
Bag
protected static final int maxSize
public boolean isEmpty()

Class Multiset is an extension of Bag. It must implement the method in Bag, and all the methods that it declares. A multiset is like a set in that the order of its elements does not matter, but it is different from a set in that it may have multiple copies of its elements.

Multiset
public Multiset()
public Multiset(Object element)
public boolean add(Object element)
public boolean delete(Object element)
public boolean equals(Multiset m)

Class Set is an extension of Multiset. It overrides the add method and inherits all the other methods from Multiset.

public Set
Set()
public Set(Object element)
public boolean add(Object element)

You should also create a class TestBag which contains the main method. It should create several instances each of Multiset and Set that contain Objects of type Character or Integer (not char or int) and demonstrate that the class methods work correctly. Each instance need only contain objects of one type. TestBag does not need to check for user errors, but depending on how you implement the assignment, your methods may need to have some checks to prevent abnormal program termination. You don't need to use try and catch blocks yet.

(b) Add comment documentation to your program (all the classes including TestBag) and use javadoc to extract the documentation into an HTML file. Include a javadoc comment for each class and each method. The class comment should include your name and the date (use the @author tag). Method comments should briefly describe the purpose of the method, its arguments, and what, if anything, it returns (using @param and @return as appropriate). Although these are small classes now, and this may seem like a lot of commenting, we will expand on this assignment at a later date.

The physical location of the javadoc comments is critical. A class comment must immediately precede the line containing the keyword class, and method comments must immediately precede the method.

When you have commented your source files, run javadoc to create the .html files and view them in a browser of your choice.


What to submit:
Your grade on the program will be based on: