Question: 2.Write an abstract class Vehicle which has two data fields: speed(int) and costPerKM(double), get/set methods for each data field and a constructor method that initializes

2.Write an abstract class Vehicle which has two data fields: speed(int) and costPerKM(double), get/set methods for each data field and a constructor method that initializes speed to 0 and costPerKM to 0.0. The vehicle class also has an abstract method getTripDuration() that has a double type parameter(for the trip distance) and return type is also double.

3. write a child class of vehicle named Plane which has a data fieild extraCost(double) and the corresponding get/set methods. The plane calss has two construtor method: a default constructor tht set/initialize speed to 0, costPerKM to 0.0, and the other constructor sets/initialize the three data fields with the corresponding paramenteres. The Plane class has another method named getCost() that has one double type parameter for the distance and retutrns the trip cost by taking a plane i:e cost=costPerKm*distance+extraCost. The class implements the getTripDuration() method that calcuklates the trip duration by adding half an hour(for taking off, landing etc.) to the normal flight duration(distance divided by speed).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!