192k views
4 votes
Suppose you run a rent-a-car company and have two types of vehicles in it: cars and jee 1. (10 points) PROBLEM ONE All vehicles have a manufacturer, mileage, capacity to fit people and fare. The basic fare all vehicles is PKR 100 for each seat. In addition to the basic fare, the cars cost 10 Write three classes Vehicle, Car and Jeep. All of the ahove attributes should be present the three and one function getFare() should return the fare of a vehicle. Use inheritence reduce the code as much as possible

1 Answer

2 votes

Final answer:

To solve this problem, we need to create three classes: Vehicle, Car, and Jeep, with specific attributes and a getFare() function. Inheritance can be used to reduce code duplication.

Step-by-step explanation:

To solve this problem, we need to create three classes: Vehicle, Car, and Jeep. All of these classes will have attributes such as manufacturer, mileage, capacity to fit people, and fare. The basic fare for all vehicles is PKR 100 for each seat. In addition to the basic fare, cars cost 10% more, while jeeps cost 20% more. To reduce code duplication, we can use inheritance. The Vehicle class will have a function called getFare() that will return the fare of a vehicle.

User JBoulhous
by
7.7k points