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

Vehicle Assignment

The document outlines a programming assignment involving the creation of a vehicle interface and its implementation in classes. It defines an interface `IVehicle` with methods for driving and refueling, and a `LandVehicle` class that inherits from this interface, including properties and methods for vehicle management. Additionally, an `Automobile` class extends `LandVehicle`, adding specific fields for tracking automobiles.

Uploaded by

birukgetubaye
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)
5 views3 pages

Vehicle Assignment

The document outlines a programming assignment involving the creation of a vehicle interface and its implementation in classes. It defines an interface `IVehicle` with methods for driving and refueling, and a `LandVehicle` class that inherits from this interface, including properties and methods for vehicle management. Additionally, an `Automobile` class extends `LandVehicle`, adding specific fields for tracking automobiles.

Uploaded by

birukgetubaye
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

Vehicle Programming Assignment

Vehicle Interface

Create an interface `IVehicle` with two methods:


- Drive() of type void
- Refuel(int amount) of type void

Code:
------
public interface IVehicle
{
void Drive();
void Refuel(int amount);
}

LandVehicle Class

The LandVehicle class inherits from IVehicle. It includes:


- Fields: brandOrModel, noOfSeats, color (private with public properties)
- Static Field: Count for tracking the number of vehicles
- Methods:
- Drive() and Refuel(int amount) implementations
- A Break() method for stopping

Code:
------
public class LandVehicle : IVehicle
{
private string brandOrModel;
private int noOfSeats;
private string color;

public string BrandOrModel { get => brandOrModel; set => brandOrModel = value; }
public int NoOfSeats
{
get => noOfSeats;
set
{
if (value < 1 || value > 70)
throw new ArgumentException("Number of seats must be between 1 and 70.");
noOfSeats = value;
}
}
public string Color { get => color; set => color = value; }

public static int Count { get; private set; }

public LandVehicle()
{
Count++;
}

public LandVehicle(string brand, int seats, string color)


{
BrandOrModel = brand;
NoOfSeats = seats;
Color = color;
Count++;
}

public void Drive()


{
[Link]($"{brandOrModel} is Driving.");
}

public void Refuel(int amount)


{
[Link]($"Refueled with {amount} liters of fuel.");
}

public void Break()


{
[Link]($"{brandOrModel} has stopped.");
}
}

Automobile Class

The Automobile class inherits from LandVehicle and implements IVehicle.


- Fields: plateNumber, ownerName
- Static Field: Count for tracking the number of automobiles.

Code:
------
public class Automobile : LandVehicle
{
public string PlateNumber { get; set; }
public string OwnerName { get; set; }

public static int AutomobileCount { get; private set; }

public Automobile()
{
AutomobileCount++;
}

public Automobile(string brand, int seats, string color, string plate, string owner)
: base(brand, seats, color)
{
PlateNumber = plate;
OwnerName = owner;
AutomobileCount++;
}
}

You might also like