adding to a collections - inheritance
<p>I am trying to make a project that adds cd / dvd /movie info from main() to a collections library
then prints info added.
like: output</p>

<pre><code>-Book-
author:   Robert A. Heinlein
# pages:  325
title:    Starship Troopers
keywords: science fiction, war, weapons

-Music-
band:     five finger death punch
# songs:  15
members:  Zoltan Bathory, Ivan Moody,Jeremy Spencer,Matt Snell,Jason Hook 
title:    War is the answer
keywords: rock
</code></pre>

<p>I currently have 6 classes</p>

<p>1.project1 - main()</p>

<p>2.Library - where im adding to database</p>

<p>3.item - inheritance(title &amp; number)</p>

<p>4.cd</p>

<p>5.dvd</p>

<p>6.movie</p>

<p>i am trying to use inheritance so i want to keep the files i have.
My question is i am trying to add to the collections in the library class. I am just not sure how to do it.</p>

<p>here is the classes i think you will need to see..</p>

<pre><code>import java.io.PrintStream;
import java.util.Collection;



public class project
{
private static Library library = new Library();

public static void main(String[] args)
{
    PrintStream out = System.out;                       // we will be printing to the standard output stream
    Item        item;



    // add items to library
    out.println("&gt;&gt;&gt; adding items to library:\n");
    item = library.addBook("The Curious Incident of the Dog in the Night-Time", "Mark Haddon", 240, "autism", "Asperger's Syndrome");
    if (item != null)
        library.printItem(out, item);
    item = library.addBook("Starship Troopers", "Robert A. Heinlein", 325, "science fiction", "war", "weapons");
    if (item != null)
        library.printItem(out, item);
    item = library.addBook("The Moon Is A Harsh Mistress", "Robert A. Heinlein", 389, "science fiction", "moon", "social structures");
    if (item != null)
        library.printItem(out, item);
    item = library.addMusicCD("Europe In '72", "Grateful Dead", 12, "acid rock", "sixties", "jam bands");
    if (item != null) {
        library.addBandMembers(item, "Jerry Garcia", "Bill Kreutzman", "Keith Godcheaux");
        library.printItem(out, item);
        }
    item = library.addMusicCD("Don't Let Go", "Jerry Garcia Band", 15, "acid rock", "jam bands");
    if (item != null) {
        library.addBandMembers(item, "Jerry Garcia", "Keith Godcheaux");
        library.printItem(out, item);
        }
    item = library.addMusicCD("Sergeant Pepper's Lonely Hearts Club Band", "Beatles", 10, "acid rock", "sixties");
    if (item != null) {
        library.addBandMembers(item, "John Lennon", "George Harrison", "Ringo Starr");
        library.printItem(out, item);
        }
    item = library.addMovieDVD("Lost In Translation", "Sofia Coppola", 14, "Japan", "loneliness");
    if (item != null) {
        library.addCast(item, "Bill Murray", "Scarlett Johansson");
        library.printItem(out, item);
        }
    item = library.addMovieDVD("Groundhog Day", "Harold Ramis", 14, "newscaster", "groundhog", "time");
    if (item != null) {
        library.addCast(item, "Bill Murray", "Andie MacDowell");
        library.printItem(out, item);
        }

    // print books, musicCDs, movies
    out.println("&gt;&gt;&gt; books:\n");
    printItems(out, library.books());
    out.println("&gt;&gt;&gt; music CDs:\n");
    printItems(out, library.musicCDs());
    out.println("&gt;&gt;&gt; movies:\n");
    printItems(out, library.movies());

    // print items for keyword
    printItemsForKeyword(out, "science fiction");
    printItemsForKeyword(out, "jam bands");
    printItemsForKeyword(out, "xxx");

    // items by artist
    out.println("&gt;&gt;&gt; books by Robert A. Heinlein:\n");
    printItems(out, library.booksByAuthor("Robert A. Heinlein"));
    out.println("&gt;&gt;&gt; music by the Grateful Dead:\n");
    printItems(out, library.musicByBand("Grateful Dead"));
    out.println("&gt;&gt;&gt; music by the Rolling Stones:\n");
    printItems(out, library.musicByBand("Rolling Stones"));
    out.println("&gt;&gt;&gt; movies by Sofia Coppola:\n");
    printItems(out, library.moviesByDirector("Sofia Coppola"));
    out.println("&gt;&gt;&gt; music by Jerry Garcia:\n");
    printItems(out, library.musicByMusician("Jerry Garcia"));
    out.println("&gt;&gt;&gt; movies with Bill Murray:\n");
    printItems(out, library.moviesByActor("Bill Murray"));
}

private static void printItemsForKeyword (PrintStream out, String keyword)
{
    Collection&lt;Item&gt;    items;

    out.printf("&gt;&gt;&gt; items for keyword: %s\n\n", keyword);
    items = library.itemsForKeyword(keyword);
    printItems(out, items);
}

private static void printItems (PrintStream out, Collection&lt;Item&gt; items)
{
    if (items != null &amp;&amp; items.size() &gt; 0)
        for (Item item : items)
            library.printItem(out, item);
    else
        out.println("none\n");
}
}
</code></pre>

<p>here is the library class where i am having trouble adding to the collections..</p>

<p>How would i add a book or a cd to the collections?</p>

<pre><code>import java.io.PrintStream;
import java.util.Collection;
import java.util.*;

public class Library
{


// returns all of the items which have the specified keyword
public Collection&lt;Item&gt; itemsForKeyword(String keyword)
{
    return null;
}

// print an item from this library to the output stream provided
public void printItem(PrintStream out, Item item)
{
}



// adds a book to the library
public Item addBook(String title, String author, int nPages, String... keywords)
{


    return null;
}

// returns all of the books by the specified author
public Collection&lt;Item&gt; booksByAuthor(String author)
{
    return null;
}

// returns all of the books in the library
public Collection&lt;Item&gt; books()
{
    return null;
}

// music-related methods

// adds a music CD to the library
public Item addMusicCD(String title, String band, int nSongs, String... keywords)
{
    Collection MusicCollection = new HashSet();

    MusicCollection.add(title);
    return null;
}

// adds the specified band members to a music CD
public void addBandMembers(Item musicCD, String... members)
{
}

// returns all of the music CDs by the specified band
public Collection&lt;Item&gt; musicByBand(String band)
{
    return null;
}

// returns all of the music CDs by the specified musician
public Collection&lt;Item&gt; musicByMusician(String musician)
{
    return null;
}

// returns all of the music CDs in the library
public Collection&lt;Item&gt; musicCDs()
{
    return null;
}

// movie-related methods

// adds a movie to the library
public Item addMovieDVD(String title, String director, int nScenes, String... keywords)
{
    return null;
}

// adds the specified actors to a movie
public void addCast(Item movie, String... members)
{
}

// returns all of the movies by the specified director
public Collection&lt;Item&gt; moviesByDirector(String director)
{
    return null;
}

// returns all of the movies by the specified actor
public Collection&lt;Item&gt; moviesByActor(String actor)
{
    return null;
}

// returns all of the movies in the library
public Collection&lt;Item&gt; movies()
{
    return null;
}   
}
</code></pre>

<p>here is the items class</p>

<pre><code>import java.io.PrintStream;
import java.util.Collection;
import java.util.*;

public class Item
{
private String title;
private int number;

public Item(String theTitle, int theNumber)
{
number = theNumber;
title = theTitle;

}

public String getTitle()
{
return title;
}

public int getNumber()
{
return number;
}

}
</code></pre>

<p>here is the cd class - the dvd class is almost identical</p>

<pre><code>import java.util.*;


public class CD extends Item
{

private String artist;
private String members;


public CD(String theTitle, String theArtist, String theMembers, int number)
{
    super(theTitle,number);
    artist = theArtist;
    members = theMembers;

}


public String getArtist()
{

    return artist;

}

public String getMembers()
{
 return members;   
}

public void print()
{
    System.out.println("-Music-");
    System.out.println("band: " + artist);
}

}
</code></pre>

<hr>

<p>I am not sure if i could combine the cd/dvd/movie classes into items class?</p>

<p>My main QUESTION is:</p>

<p>how should i add each cd/dvd to collections?????</p>

<p>in the library class</p>

<p>would i just define a collection to add in every addfunction(addMusicCD,addBandMembers,addMovieDVD,etc..) or should i put the collection in the beginning of the class? and how do i add to that collection???</p>

<pre><code>public Item addMusicCD(String title, String band, int nSongs, String... keywords)
{
  Collection MusicCollection = new HashSet(); // how should i add each cd/dvd to collections?????

  MusicCollection.add(title);
  return null;
}
</code></pre>

<p>I am also trying to return an Item and cannot! what item would i need to return??
I know this is alot of information. Sorry.
Hopefully someone can help me and not just make fun of me. i am trying to learn java   from c++</p>

<p>Thank you for any help you can give me..</p>
