-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWheel.cs
75 lines (65 loc) · 2.24 KB
/
Wheel.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Text;
namespace Ex03.GarageLogic
{
public class Wheel // to check if the user adding 1 wheel or the whole 4 !
{
// $G$ NTT-999 (-3) This kind of field should be readonly.
private string m_ManufactorName;
private float m_AirPressure;
// $G$ DSN-999 (-4) The "maximum air pressure" field should be readonly member of class wheel.
private float m_MaxAirPressure;
public Wheel(string i_ManufactorName, float i_AirPressure, float i_MaxAirPressure)
{
m_ManufactorName = i_ManufactorName;
m_AirPressure = i_AirPressure;
m_MaxAirPressure = i_MaxAirPressure;
}
public string ManufactorName
{
get{ return m_ManufactorName; }
set { m_ManufactorName = value; }
}
public float AirPressure
{
get { return m_AirPressure; }
set
{
if (value > m_MaxAirPressure)
{
Exception ex = new Exception("value out of range !");
throw new ValueOutOfRangeException(ex, 0, m_MaxAirPressure);
}
else
{ m_AirPressure = value; }
}
}
public float MaxAirPressure
{
get { return m_MaxAirPressure; }
}
public void FillAir(float i_AirToAdd)
{
try{
m_AirPressure = m_AirPressure + i_AirToAdd;
}
catch(ValueOutOfRangeException ex)
{
throw ex;
}
}
public void FillAirToMax()
{
m_AirPressure = MaxAirPressure;
}
public override string ToString()
{
string output = string.Format("Manufactor Name : {0}" + Environment.NewLine + "Air Pressure : {1}" +
Environment.NewLine +
"Max Air Pressure : {2}" + Environment.NewLine,
m_ManufactorName, m_AirPressure, m_MaxAirPressure);
return output;
}
}
}