JAV ASSIGNMENT
Write a Java program to manage different types of vehicles using inheritance and abstract classes.
Requirements:
1. Create an abstract class Vehicle with the following:
• Fields for make (String), model (String), and year (int).
• An abstract method void startEngine() to define how the vehicle's engine starts.
• A constructor to initialize the fields.
2. Create two subclasses of Vehicle:
• Car:
• Implements the startEngine() method to print: "Car engine started with a key."
• Motorcycle:
• Implements the startEngine() method to print: "Motorcycle engine started with a kick."
3. In the main method of a TestVehicle class:
• Create objects of Car and Motorcycle.
• Call the startEngine() method on each object to display how the vehicle starts.
// Abstract class Vehicle
public abstract class Vehicle {
private String make;
private String model;
private int year;
// Constructor to initialize fields
public Vehicle(String make, String model, int year) {
[Link] = make;
[Link] = model;
[Link] = year;
// Abstract method to start the engine
public abstract void startEngine();
// Subclass Car
class Car extends Vehicle {
public Car(String make, String model, int year) {
super(make, model, year);
@Override
public void startEngine() {
[Link]("Car engine started with a key.");
// Subclass Motorcycle
class Motorcycle extends Vehicle {
public Motorcycle(String make, String model, int year) {
super(make, model, year);
}
@Override
public void startEngine() {
[Link]("Motorcycle engine started with a kick.");
// Test class
public class TestVehicle {
public static void main(String[] args) {
// Create objects of Car and Motorcycle
Vehicle myCar = new Car("Toyota", "Corolla", 2020);
Vehicle myMotorcycle = new Motorcycle("Harley-Davidson", "Sportster", 2021);
// Call the startEngine() method on each object
[Link](); // Output: Car engine started with a key.
[Link](); // Output: Motorcycle engine started with a kick.
GROUP MEMBERS ID NUMBERS
[Link] MELKAMU 1506867
[Link] AWOKE 1506196
[Link] ADANE 1506197
[Link] WAGNEW 1506283
[Link] BIRHAN 1506208
[Link] SIMEGNEW 1506385
[Link] ASMAMAW 1507023
[Link] ADANE 1507033
Submitted date 14/05/2017 EC