PDA

View Full Version : Confused as to what this means.


ThomasWint
03-14-2010, 04:45 AM
I've got an assignment to do, but I'm really confused on how to start, and was wondering if someone could help me out (as I can't reach my teacher right now). The assignment says, "construct a CDCollection class that holds a collection of CD's" and he gives us the java file for CD's.

Now my question, is CDCollection a subclass of CD's, or is it the opposite? I can't figure it out, and can't get started until I do. Can someone help me please?

-Thank you.

Old Pedant
03-14-2010, 06:06 AM
Neither.

It is exactly what he says.

A *separate* class that is a *collection*. Where each element *OF* that collection is a reference to a CD object (to an instance of the CD class).

What is a collection? Anything that holds 0 or more object references.

The simplest possible collection would be an array. In your case, an array of CD object references. Wouldn't even have to be a class, as an array is a built-in mechanism of Java. But an array is also not very flexible. Think what kinds of thing you would want to do with a *physical* collection of CDs: You'd like to add a CD to the collection (you bought a new one), remove a CD from the collection (you sold or gave away one), find a CD by title or artist or label in the collection, list the contents of the collection in order by title or artist or label. And probably more. Now, construct a Java class that mimics those possible actions.