-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarStructure.cs
More file actions
64 lines (53 loc) · 1.72 KB
/
Copy pathCarStructure.cs
File metadata and controls
64 lines (53 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
namespace CS_cars
{
public abstract class ElectricCar : ACar, IElectric
{
public int BatteryKilowattHours { get; init; }
protected ElectricCar(string make, string model, int seats, ITransmission transmission, int year, string color, int battery)
: base(make, model, seats, transmission, year, color)
{
BatteryKilowattHours = battery;
}
public override int GetMaxSpeed()
{
return (int)(BatteryKilowattHours * 2.5);
}
public override string GetSafetyRating()
{
if (BatteryKilowattHours > 90) return "5 stars";
if (BatteryKilowattHours > 60) return "4 stars";
return "3 stars";
}
public override string GetDescription()
{
return base.GetDescription() + $", electrical car with {BatteryKilowattHours} kWh battery";
}
public override string GetEngineType() => "Electric";
}
public abstract class GasCar : ACar, IGas
{
public string EngineType { get; init; }
public int Horsepower { get; init; }
protected GasCar(string make, string model, int seats, ITransmission transmission, int year, string color, string engineType, int hp)
: base(make, model, seats, transmission, year, color)
{
EngineType = engineType;
Horsepower = hp;
}
public override string GetDescription()
{
return base.GetDescription() + $", gas car with {EngineType}, {Horsepower} HP";
}
public override int GetMaxSpeed()
{
return (int)(Math.Cbrt(Horsepower) * 3.5);
}
public override string GetSafetyRating()
{
if (Horsepower > 400) return "5 stars";
if (Horsepower > 200) return "4 stars";
return "3 stars";
}
public override string GetEngineType() => EngineType;
}
}