Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The key points are:Inheritance, Introduce Inheritance, Superclasses, Polymorphic Data Structures, Subclasses, Wrapper Classes, Inheritance Hierarchies, Classes and Types, Object Class, Collections and Primitive Types
Typology: Slides
1 / 56
public void setComment(String com) { comment = com; }
public String getComment() { return comment; }
public void setOwn(boolean ownIt) // set the flag indicating whether we own this CD. { gotIt = ownIt; }
public boolean getOwn() // return true if we own a copy of this CD. { return gotIt; }
public void print() // print details about this CD { System.out.print("CD: " + title + " (" + playingTime + " mins)"); if (gotIt) System.out.println("*"); else System.out.println(); System.out.println(" " + artist); System.out.println(" tracks: " + numberOfTracks); if (comment != null) System.out.println(" " + comment); } // end of print()
} // end of CD class
public void setComment(String com)
{ comment = com; }
public String getComment()
{ return comment; }
public void setOwn(boolean ownIt)
// set the flag indicating whether we own this DVD.
{ gotIt = ownIt; }
public boolean getOwn()
// return true if we own a copy of this DVD.
{ return gotIt; }
public void print() // print details about this DVD { System.out.print("DVD: " + title + " (" + playingTime + " mins)"); if (gotIt) System.out.println("*"); else System.out.println(); System.out.println(" " + director); if (comment != null) System.out.println(" " + comment); } // end of print()
} // end of DVD class
public void list() // print a list of all currently stored CDs and DVDs { for (CD cd : cds) cd.print();
for (DVD dvd : dvds) dvd.print(); } // end of list()
} // end of Database class
public class UseDome
{
public static void main(String[] args) { Database db = new Database();
CD beatles = new CD("the white album", "the beatles",13, 122); db.addCD( beatles); beatles.setComment("the best of the later period");
db.addCD( new CD("morrison hotel", "the doors", 11, 109)); db.addCD( new CD("dark side of the moon","pink floyd",9,100)); :