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

Generic Approch

Uploaded by

adilisdb
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)
18 views3 pages

Generic Approch

Uploaded by

adilisdb
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

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Evidence_Exam_Generic_Approch
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");

Car<string> car = new Car<string>("COROLA", 25000000, 2021, 40.5F, "GAS", "Color: Rad",
"Seat Color: Black", "Headlight: LED");

car.Display();

Motorcycle<string> motor = new Motorcycle<string>("Yamaha", 240000, 2020, 80.5F, "Octen",


"Color: Blue", "Headlight: LED");

motor.Display();
Console.Read();
}
}
public enum VehicleType
{
FourWheeler,
TwoWheeler
}

public abstract class Vehicle


{

public string Model { get; set; }


public decimal Price { get; set; }
public int YearMake { get; set; }

public float Mileage { get; set; }


public string FuelType { get; set; }
public VehicleType VehicleType { get; set; }

protected Vehicle(string model, decimal price, int year, float mileage, string fuel, VehicleType
VehicleType)
{
this.Model = model;
this.Price = price;
this.YearMake = year;
this.Mileage = mileage;
this.FuelType = fuel;
this.VehicleType = VehicleType;
}
public abstract void Display();

public interface IFourWheeler<T> where T : class


{
T[] InteriorDesign { get; set; }
}
public class FourWheeler<T> : Vehicle, IFourWheeler<T> where T : class
{
public T[] InteriorDesign { get; set; }
public FourWheeler(string model, decimal price, int year, float mileage, string fuel, params T[]
InteriorDesign) : base(model, price, year, mileage, fuel, VehicleType.FourWheeler)
{
this.InteriorDesign = InteriorDesign;
}

public override void Display()


{

}
}
public sealed class Car<T> : FourWheeler<T> where T : class
{
public Car(string model, decimal price, int year, float mileage, string fuel, params T[] InteriorDesign) :
base(model, price, year, mileage, fuel, InteriorDesign)
{}
public override void Display()
{
Console.WriteLine("Car info:");
Console.WriteLine("Type:" + this.VehicleType);
Console.WriteLine("Model:" + this.Model);
Console.WriteLine("Price:" + this.Price);
Console.WriteLine("Year:" + this.YearMake);
Console.WriteLine("Mileage:" + this.Mileage);
Console.WriteLine("Fuel:" + this.FuelType);
foreach (var design in this.InteriorDesign)
{
Console.WriteLine(design);
}
Console.WriteLine();
}
}
public interface ITwoWheeler<T> where T : class
{
T[] ExteriorDesign { get; set; }
}
public class TwoWheeler<T> : Vehicle, ITwoWheeler<T> where T : class
{
public T[] ExteriorDesign { get; set; }
public TwoWheeler(string model, decimal price, int year, float mileage, string fuel, params T[]
ExteriorDesign) : base(model, price, year, mileage, fuel, VehicleType.TwoWheeler)
{
this.ExteriorDesign = ExteriorDesign;
}
public override void Display()
{
}
}
public sealed class Motorcycle<T> : TwoWheeler<T> where T : class
{
public Motorcycle(string model, decimal price, int year, float mileage, string fuel, params T[]
ExteriorDesign) : base(model, price, year, mileage, fuel, ExteriorDesign)
{}
public override void Display()
{
Console.WriteLine("Motorcycle info:");
Console.WriteLine("Type:" + this.VehicleType);
Console.WriteLine("Model:" + this.Model);
Console.WriteLine("Price:" + this.Price);
Console.WriteLine("Year:" + this.YearMake);
Console.WriteLine("Mileage:" + this.Mileage);
Console.WriteLine("Fuel:" + this.FuelType);
foreach (var design in this.ExteriorDesign)
{
Console.WriteLine(design);
}
Console.WriteLine();
}
}
}

You might also like