Classe ElectronicProducts:
namespace exercise73.Models;
internal class ElectronicProducts
{
public string Brand { get; set; }
public string Model { get; set; }
public double Price { get; set; }
public ElectronicProducts(string brand, string model, double price)
{
Brand = brand;
Model = model;
Price = price;
}
public virtual string DisplayInformation()
{
return $"Brand: {Brand}, Model: {Model}, Price: {Price:F2}";
}
}
Classe Smartphone:
namespace exercise73.Models;
internal class Smartphone : ElectronicProducts
{
public string OperatingSystem { get; set; }
public Smartphone(string brand, string model, double price, string operatingSystem)
: base(brand, model, price)
{
OperatingSystem = operatingSystem;
}
public override string DisplayInformation()
{
return $"{base.DisplayInformation()}, Operating System: {OperatingSystem}.";
}
}
Classe Tablet:
namespace exercise73.Models;
internal class Tablet : ElectronicProducts
{
public string ScreenType { get; set; }
public Tablet(string brand, string model, double price, string screenType)
: base(brand, model, price)
{
ScreenType = screenType;
}
public override string DisplayInformation()
{
return $"{base.DisplayInformation()}, Screen Type: {ScreenType}.";
}
}
Classe Laptop:
namespace exercise73.Models;
internal class Laptop : ElectronicProducts
{
public string OperatingSystem { get; set; }
public Laptop(string brand, string model, double price, string operatingSystem)
: base(brand, model, price)
{
OperatingSystem = operatingSystem;
}
public override string DisplayInformation()
{
return $"{base.DisplayInformation()}, Operating System: {OperatingSystem}.";
}
}
Instâncias:
using exercise73.Models;
Smartphone smartphone = new Smartphone("Samsung", "A15", 1500, "Android");
Console.WriteLine(smartphone.DisplayInformation());
Console.WriteLine();
Laptop laptop = new Laptop("Dell", "Inspiron 15", 4000.00, "Windows");
Console.WriteLine(laptop.DisplayInformation());
Console.WriteLine();
Tablet tablet = new Tablet("Samsung", "Galaxy Tab S10", 3000.00, "Immersive");
Console.WriteLine(tablet.DisplayInformation());
Console.WriteLine();