Tausif K.

asked • 11/20/20

java program to

(a) Create an abstract class Instrument which is having the abstract function play. Create three more sub classes from Instrument which is Piano, Flute and Guitar. Override the play method inside all three classes printing a message. “Piano is playing  tan tan tan tan”  for Piano class “Flute is playing  toot toot toot toot”  for Flute class “Guitar is playing  tin  tin  tin”  for Guitar class You must not allow the user to declare an object of Instrument class. Create an array of 10 Instruments. Assign different type of instrument to Instrument reference. Check for the polymorphic behavior of play method. Use the instanceof operator to print that which object stored at which index of instrument array.        08 10 1,2 8,9 8/7/2020 Academic Documents (A-Z): L. Laboratory Manuals https://lms.nirmauni.ac.in/mod/book/view.php?id=2630&chapterid=1760 6/14.

(b) Create an abstract class Compartment to represent a rail coach. Provide an abstract function notice in this class. Derive FirstClass, Ladies, General and Luggage classes from the compartment class. Override the notice function in each of them to print notice suitable to the type of the compartment. Create a class TestCompartment. Write main function to do the following: Declare an array of Compartment pointers of size 10. Create a compartment of a type as decided by a randomly generated integer in the range 1 to 4. Check the polymorphic behavior of the notice method.

(c) Consider an example of declaring the examination result. Design three classes: Student, Exam, and Result. The Student class has data members such as those representing roll number, name etc. Create the class Exam by inheriting the Student class. The Exam class adds fields representing the marks scored in six subjects. Derive the Result from the Exam class and it has its own fields such as total_Marks. Write an interactive program to model this relationship.

(d) Create a class Medicine to represent a drug manufactured by a pharmaceutical company. Provide a function displayLabel( ) in this class to print Name and address of the company. Derive Tablet, Syrup and Ointment classes from the Medicine class. Override the displayLabel( ) function in each of these classes to print additional information suitable to the type of medicine. For example, in case of tablets, it could be “store in a cool dry place”, in case of ointments it could be “for external use only” etc. Create a class TestMedicine. Write main function to do the following: Declare an array of Medicine references of size 10 Create a medicine object of the type as decided by a randomly generated integer in the range 1 to 3. Check the polymorphic behavior of the displayLabel( ) method.

(e) Create a class Car which contains members speed, noOfGear. The class has a method drive( ) which is responsible to provide starting speed and noOfGears to a Car.  Implement display( ) method which will display all attributes of Car class. The class SportCar is derived from the class Car which adds new features AirBallonType. When this method is invoked, initial speed and gear status must be displayed on console.  Override the display method which display all attribute of the SportCar. Make use of super class display( ) method. (e) A super class Record has been defined to store the names and ranks of 50 students. Define a sub class Rank to find the highest rank along with the name. The details of both classes are given below: Class name : Record Data Members / instance variables: ·         name[ ] : to store the names of students 8/7/2020 Academic Documents (A-Z): L. Laboratory Manuals https://lms.nirmauni.ac.in/mod/book/view.php?id=2630&chapterid=1760 7/14 ·         rnk[ ] : to store the ranks of students Member functions: ·         Record( ) : constructor to initialize data members ·         void readvalues( ) : to store names and ranks ·         void display( ) : displays the names and the corresponding ranks Class name : Rank Data Members / instance variables: ·         index : integer to store the index of the topmost rank Member functions ·         Rank( ) : constructor to invoke the base class constructor and to initialize index to 0. ·         void highest( ) : finds the index location of the topmost rank and stores it in index without sorting the array 6 ·         void display( ) : displays the name and ranks along with the name having the topmost rank. Specify the class Record giving details of the constructor( ), void readvalues( ), void display( ). Using the concept of inheritance, specify the class Rank giving details of constructor( ), void highest( ) and void display( ).

1 Expert Answer

By:

Patrick B. answered • 11/21/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Patrick B.

ALL of this code is not going to fit here.... Please send email so I can pass you the source code files
Report

11/21/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.