-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFuelEngine.cs
57 lines (50 loc) · 1.73 KB
/
FuelEngine.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
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Text;
namespace Ex03.GarageLogic
{
public class FuelEngine : Engine
{
// $G$ CSS-003 (-3) Bad readonly members variable name (should be in the form of r_PamelCase).
private readonly eFuelType m_FuelType;
private float m_CurrentFuel;
private float m_MaxAmountOfFuel;
public FuelEngine(eFuelType i_FuelType, float i_CurrentFuel, float i_MaxAmountOfFuel)
{
m_FuelType = i_FuelType;
m_CurrentFuel = i_CurrentFuel;
m_MaxAmountOfFuel = i_MaxAmountOfFuel;
}
public eFuelType FuelType
{
get { return m_FuelType; }
}
public float MaxAmountOfFuel
{
get { return m_MaxAmountOfFuel; }
}
public float Fuel
{
get { return m_CurrentFuel; }
set
{
if (value > m_MaxAmountOfFuel || value < 0)
{
Exception ex = new Exception("value out of range !");
throw new ValueOutOfRangeException(ex, 0, m_MaxAmountOfFuel);
}
else
{
m_CurrentFuel = value;
}
}
}
public override string ToString()
{
string output = string.Format(Environment.NewLine + "Fuel Type : {0} " + Environment.NewLine
+ "Current Fuel : {1}" + Environment.NewLine +
"Max amount of fuel : {2} " + Environment.NewLine, m_FuelType, m_CurrentFuel, m_MaxAmountOfFuel);
return output;
}
}
}