304311 Java Lab 

Lab 6

Objective

To introduce inheritance

Classwork:

  1. Imagine a publishing company that markets both book and audiocassette versions of its works. Create a class Publication that stores the title          ( type String ) and price ( type float ) of a publication. From this class derive two classes: Book, which adds pages count ( type int ); and Tape, which adds a playing time in minutes ( type float ). Each of these three classes should have  get  and  set  functions. Also they should have an overridden function toString to display the data. Write an application TestInheritance to test the Book and Tape classes by creating instances of them, and displaying there data. Use an instance of class DecimalFormat to format any float number to be displayed with two digits to the right of the decimal point. The figure bellow show a sample output:

 

 

Lab 1
Lab 2
Lab 3
Lab 4
Lab 5
Lab 6
Lab 7
Lab 8
Lab 9

 � All Copyright Reserved By Fatma & Tahany,Email : [email protected]

Hosted by www.Geocities.ws

1