I have created two classes CD and DVD with the following attributes.
CD: title, playingtime, gotit, comment, artist, numberOftracks
Video: title, playingtime, gotit, comment, director
I've also written getter and setter methods for each attribute.
Also I have written constructors for each class. The constructors take all the attributes as parameter. The signature of these paramenters are;
CD(String title, int playingtime, boolean gotit, String comment, String artist, int numberOftracks)
Video(String title, int playingtime, boolean gotit, String comment, String director)
[u]Stuck on these following questions especially the inheritance code.[/u] [/b]
iv. Add a method print() in each class that prints all the attributes of the class.
v. You may have noticed that CD and Video classes contains some common attributes. These common attributes lead to duplicate code.
vi. [color=Red]Use inheritance to reduce the code duplication.[/color] This will involve creating a new parent class Item and making CD and DVD classes as its child class.
vii. You may also have noticed that the print method in both the CD and DVD classes contain some duplicate code. Use inheritance to reduce this duplicate code. This will involve creating a print() method in the parent class Item.