Assignment 5
Assignment 5
1. Write a Java program to create a class called Shape with methods called
getPerimeter() and getArea(). Create a subclass called Circle that
overrides the getPerimeter() and getArea() methods to calculate the area
and perimeter of a circle.
2. Write a Java program to create a vehicle class hierarchy. The base class
should be Vehicle, with subclasses Truck, Car and Motorcycle. Each
subclass should have properties such as make, model, year, and fuel type.
Implement methods for calculating fuel efficiency, distance traveled, and
maximum speed.
cargoCapacity for truck
NoOfSits for car
EngineDisplacement for MotorCycle
Note: Fuel efficiency = Divide the number of kilometers by the number of litres
consumed
3. Write a Java program to create a class known as "BankAccount" with
methods called deposit() and withdraw() and members accountNumber
and balance. Create a subclass called SavingsAccount that overrides the
withdraw() method to prevent withdrawals if the account balance falls
below one hundred.