Question: java language Assignment 11 - Polymorphism Create the following classes which form a hierarchy of vehicles. 1. Create an abstract class Vehicle which has properties
Assignment 11 - Polymorphism Create the following classes which form a hierarchy of vehicles. 1. Create an abstract class Vehicle which has properties speed, maxSpeed, model and manufacturer. Vehicle will have the following abstract methods (a) increase: This method takes an integer, incr, which specifies the required increment in the speed. (b) decrease: This method takes an integer, decr, which specifies the required decrement in the speed (c) displaySpeed: This method will display the speed Note that the above descriptions is intended for subclasses of the class Vehicle. 2. Extend the class Vehicle to a class Car which has properties color and year. 3. Extend the class Vehicle to a class Boat which has properties name, and IsSailboat. 4. Extend the class Vehicle to a class Airplane which has a property elevation indicating current elevation of the airplane. 5. Subclasses will define the methods increase (double incr) and decrease (double decr) to increase and decrease the speed of the vehicle by the given amount. Speed cannot be increased beyond the maximum speed. 6. Subclasses method displaySpeed ( ) which will display a message indicating the speed of the vehicle. Examples of messages are: Blue 2007 Lexus LS200 is cruising at 90 km/hour. Sailboat Morning Star is sailing at 10 knots. Boeing 737 is flying at 700 miles/hour at elevation 30000 feet. Write a program to test the Vehicle classes: 7. Create an array, vehicles, and initialize the elements of the array to various types of Car, Boat and Airplane objects. 8. Call various methods of the elements of the vehicles array to change the speed of the vehicles. 9. Finally, traverse all the elements of the vehicles array and display the speed of each of the vehicles. Note that this will exploit the polymorphic feature of the class hierarchy
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
