Problem Statement:
Keeping in view the above class diagram, you have to write code for the below mentioned classes and show their relationship with each other:
1. Class Vehicle:
Attribute:
vehicleNo: string
color: string
Methods/Operations/Getters/Setters:
getVehicleNo(): string
getColor(): string
2. Class Car:
distance: int
Methods/Operations/Getters/Setters:
setDistance(int): void
calculateFare(int): int
displayInformation(): void
Important points:
Your program should be able to create a Car object having a number, color and distance without creating an explicit object of Vehicle class.
All Vehicle attributes should be directly accessible to Car and should not be accessible publically.
Your program should accept value of distance only between 1-500 kilometers; any other value should be treated as invalid value.
At the end, information about Car (car number, car color, distance covered) and total fare should be displayed whereas calculateFare(int) is a utility function. Fare is 5 rupees/kilometer.
Sponsored Links