0% found this document useful (0 votes)
3 views2 pages

Vehicle Fuel Efficiency Calculator

Uploaded by

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

Vehicle Fuel Efficiency Calculator

Uploaded by

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

using System;

public class Vehicle


{
public string model;
public int year;
public char fuelType; // P = Petrol, O = Octane, G = Gas

public void CalculateFuelEfficiency()


{
[Link]($"Enter distance traveled for {model} (km or miles): ");
double distance = [Link]([Link]());

[Link]($"Enter fuel used for {model} (liters or gallons): ");


double fuel = [Link]([Link]());

if (fuel > 0)
{
double efficiency = distance / fuel;
[Link]($"{model} Fuel Efficiency: {efficiency} km/l or
mpg");
}
else
{
[Link]("Fuel used must be greater than zero.");
}
}
}

public class Truck : Vehicle


{
public Truck()
{
model = "HeavyR1";
year = 2025;
fuelType = 'P'; // Petrol
}
}

public class Car : Vehicle


{
public Car()
{
model = "BMWZ4";
year = 2025;
fuelType = 'G'; // Gas
}
}

public class Motorcycle : Vehicle


{
public Motorcycle(string model,int year,char fuelType)
{
model = model;
year = year;
fuelType = fuelType;
}
}
class Program
{
static void Main()
{

Truck truck = new Truck();


Car car = new Car();
Motorcycle motorcycle = new Motorcycle("ABc",2024,'A');

[Link]();
[Link]();
[Link]();
}
}

You might also like