0% found this document useful (0 votes)
2 views4 pages

Java

The document outlines a Java assignment to create a vehicle management program using inheritance and abstract classes. It specifies the creation of an abstract class 'Vehicle' with fields for make, model, and year, along with an abstract method for starting the engine, and two subclasses 'Car' and 'Motorcycle' that implement this method. Additionally, a 'TestVehicle' class is provided to instantiate the vehicles and demonstrate the engine start functionality, along with a list of group members and their ID numbers.

Uploaded by

Mairegu Melkamu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Java

The document outlines a Java assignment to create a vehicle management program using inheritance and abstract classes. It specifies the creation of an abstract class 'Vehicle' with fields for make, model, and year, along with an abstract method for starting the engine, and two subclasses 'Car' and 'Motorcycle' that implement this method. Additionally, a 'TestVehicle' class is provided to instantiate the vehicles and demonstrate the engine start functionality, along with a list of group members and their ID numbers.

Uploaded by

Mairegu Melkamu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like