-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElectricEngine.cs
49 lines (44 loc) · 1.39 KB
/
ElectricEngine.cs
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
using System;
using System.Collections.Generic;
using System.Text;
namespace Ex03.GarageLogic
{
public class ElectricEngine :Engine
{
private float m_BatteryTimeLeft;
private readonly float m_MaxBaterryTime;
public ElectricEngine(float i_BatteryTimeLeft, float i_MaxBaterryTime)
{
m_BatteryTimeLeft = i_BatteryTimeLeft;
m_MaxBaterryTime = i_MaxBaterryTime;
}
public float MaxBattery
{
get { return m_MaxBaterryTime; }
}
public float Battery
{
get { return m_BatteryTimeLeft; }
set {
if (value > m_MaxBaterryTime)
{
Exception ex = new Exception("value out of range !");
throw new ValueOutOfRangeException(ex, 0, m_MaxBaterryTime);
}
else
{
m_BatteryTimeLeft = value;
}
}
}
public override string ToString()
{
string output = string.Format(Environment.NewLine + "electric engine : " + Environment.NewLine + "Battery time left : {0}" +
Environment.NewLine +
"Maximum battery time : {1}" + Environment.NewLine,
m_BatteryTimeLeft,
m_MaxBaterryTime);
return output;
}
}
}