Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views3 pages

F018 Aditya Sharma Oop Lab 09

The document presents a Java implementation of an object-oriented programming lab focused on vehicle management. It includes an abstract class 'Vehicle', an interface 'FuelEfficiency', and two concrete classes 'Car' and 'Bike' that extend the Vehicle class and implement the FuelEfficiency interface. The main class demonstrates the creation of Car and Bike objects, displaying their information and calculating their fuel efficiency.

Uploaded by

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

F018 Aditya Sharma Oop Lab 09

The document presents a Java implementation of an object-oriented programming lab focused on vehicle management. It includes an abstract class 'Vehicle', an interface 'FuelEfficiency', and two concrete classes 'Car' and 'Bike' that extend the Vehicle class and implement the FuelEfficiency interface. The main class demonstrates the creation of Car and Bike objects, displaying their information and calculating their fuel efficiency.

Uploaded by

Assassin Hackers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP LAB 09

Name: Aditya Sharma Roll Number: F018


Sem/Batch: Sem 8/F1 Date: 11/04/2025

abstract class Vehicle {​


protected String brand;​
protected String model;​
protected int year;​


public Vehicle(String brand, String model, int year) {​
this.brand = brand;​
this.model = model;​
this.year = year;​
}​


public abstract void displayInfo();​
}​


interface FuelEfficiency {​
double calculateFuelEfficiency();​
}​


class Car extends Vehicle implements FuelEfficiency {​
private double fuelConsumed;​
private double distanceTraveled;​
public Car(String brand, String model, int year, double fuelConsumed, double
distanceTraveled) {​
super(brand, model, year);​
this.fuelConsumed = fuelConsumed;​
this.distanceTraveled = distanceTraveled;​
}​


@Override​
public void displayInfo() {​
System.out.println("Car Brand: " + brand);​
System.out.println("Model: " + model);​
System.out.println("Year: " + year);​
}​


@Override​
public double calculateFuelEfficiency() {​
return distanceTraveled / fuelConsumed;​
}​
}​

// Concrete Class Bike​
class Bike extends Vehicle implements FuelEfficiency {​
private double fuelConsumed; // in liters​
private double distanceTraveled; // in kilometers​

// Constructor to initialize bike details​
public Bike(String brand, String model, int year, double fuelConsumed,
double distanceTraveled) {​
super(brand, model, year);​
this.fuelConsumed = fuelConsumed;​
this.distanceTraveled = distanceTraveled;​
}​


@Override​
public void displayInfo() {​
System.out.println("Bike Brand: " + brand);​
System.out.println("Model: " + model);​
System.out.println("Year: " + year);​
}​


@Override​
public double calculateFuelEfficiency() {​
return distanceTraveled / fuelConsumed;​
}​
}​

// Main Class to Test the System​
class VehicleManagementSystem {​
public static void main(String[] args) {​
// Create a Car and a Bike object​
Car car = new Car("Toyota", "Camry", 2020, 50, 600);​
Bike bike = new Bike("Yamaha", "FZ", 2018, 10, 250);​

// Display car information​
car.displayInfo();​
System.out.println("Fuel Efficiency (Car): " +
car.calculateFuelEfficiency() + " km/l\n");​

// Display bike information​
bike.displayInfo();​
System.out.println("Fuel Efficiency (Bike): " +
bike.calculateFuelEfficiency() + " km/l");​
}​
}

You might also like