I created 4 classes: Cd, Dvd, Item and Database. Cd and Dvd extend from Item. The Database class stores an ArrayList of Items.
I'm stuck on creating a method in the Database class, which calls the method display in either Cd or Dvd. However I managed to display the Cds.
How can display all items? E.g.
Item number = 1
CDItem number = 2
DVDItem number = 3
Cd
Many thanks.
Edit:
The display methods are different in Cd and Dvd.
public void displayAll() {
for (int i = 0; i < items.size(); i++) {
Cd theCd = (Cd) items.get(i);
// Dvd theDVD = (Dvd) items.get(i);
System.out.println("Item Number = " + i);
theCd.display();
// theDvd.display
}
}
My class diagram is:
Class Diagram http://img571.imageshack.us/img571/1460/unledsca.png