Homework 10 - The Collectors
Due: Monday, April 18, 2005th, 2004

The Assignment

This assignment is part of what will be a multi-part assignment. Ultimately, it will model a collection of Collectors, each of whom attempts to obtain her/his ideal collection, buy buying and selling Collectables items.

This part of the assignment asks you to build the Collectable class and the CollectableList class. In order to facilitate the final assignment, the CollectableList needs to be read in from a file.

You are also asked to build a TestDriver class with a static main() method to demonstrate that it works.

The Collectable class

The Collectable class should model an item of interest to a collector. It should have a wellKnownName, a quantity of whole items, a buyPrice in dollars (and cents as fractions thereof), and a sellPrice, also in dollars and fractions thereof.

This class should have a constructor that initializes all of these properites, a toString(), and equals(), and a compareTo(). The compareTo() should be on the basis of the wellKnownName.

The CollectableList class

The CollectableList class should model a list of collectable items. The list should have a toString() method. In addition, it should have static methods that, given two lists, can find the common items, the items that exist in one class, or the other, but not both, and the items present in either of the classes.

The class should also have a constructor that builds the list given a String fileName. The format of the file should be as follows:

The following is an example of such as file:

  2
  Yellow Tang
  2
  15.00
  25.00
  Flame Angel
  1
  50.00
  75.00
  

It has been a while since we've done file I/O -- and we've never done a lab with it. So, let me give you a quick reminder:

  import java.io.*;

  ...

  String filename = "Data.txt"; // Or, use args[0]
  File inputFile = new File (fileName);
  FileReader reader = new FileReader (inputFile);
  BufferedReader br = new BufferedReader (reader);

  ...

  // Or, in one line 
  BufferedReader br = new BufferedReader (new FileReader (new File(args[0])));
  

The TestDriver class

This should simply read in two files, and then perform each of the required operations upon them. After each operation, it should print the resulting list to the console.