Saturday 17 September 2011

EX 6


5. Design a Vehicle class hierarchy in Java. Write a test program to demonstrate
Polymorphism.

ALGORITHM
STEP 1: Create an abstract class named vehicle with abstract method Display and a
              concrete method Input.
STEP 2: Define the input method by prompting the user to enter the values for name,
               owner, type, number, engine capacity, seating capacity for the vehicle; all the
               inputs taken in the form string.
STEP 3: Extend three classes namely Air, Water and Land from the base class.
STEP 4: Define the method display under the class Air by displaying all the entered
               values.
STEP 5: Repeat step 4 for the class Water.
STEP 6: Extend the input method for the class Land by taking in the value of wheeling
               capacity for the vehicle in the form of string.
STEP 7: In the main method create a reference for the abstract class and create a switch
               case to perform operations on the opted class.
STEP 8: Under each class create a switch case to either enter the data or to display the
                transport report.
STEP 9: Repeat the main menu on the user's choice.
STEP 10: Create array of objects under each class and call the methods by assigning the
                  values of the created objects to the reference object, to show polymorphism.


0 comments:

Post a Comment