-
-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathRemoteControlCleanup.cs
79 lines (63 loc) · 1.59 KB
/
RemoteControlCleanup.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
76
77
78
79
public class RemoteControlCar
{
public string CurrentSponsor { get; private set; }
private Speed currentSpeed;
// TODO encapsulate the methods suffixed with "_Telemetry" in their own class
// dropping the suffix from the method name
public void Calibrate_Telemetry()
{
}
public bool SelfTest_Telemetry()
{
return true;
}
public void ShowSponsor_Telemetry(string sponsorName)
{
SetSponsor(sponsorName);
}
public void SetSpeed_Telemetry(decimal amount, string unitsString)
{
SpeedUnits speedUnits = SpeedUnits.MetersPerSecond;
if (unitsString == "cps")
{
speedUnits = SpeedUnits.CentimetersPerSecond;
}
SetSpeed(new Speed(amount, speedUnits));
}
public string GetSpeed()
{
return currentSpeed.ToString();
}
private void SetSponsor(string sponsorName)
{
CurrentSponsor = sponsorName;
}
private void SetSpeed(Speed speed)
{
currentSpeed = speed;
}
}
public enum SpeedUnits
{
MetersPerSecond,
CentimetersPerSecond
}
public struct Speed
{
public decimal Amount { get; }
public SpeedUnits SpeedUnits { get; }
public Speed(decimal amount, SpeedUnits speedUnits)
{
Amount = amount;
SpeedUnits = speedUnits;
}
public override string ToString()
{
string unitsString = "meters per second";
if (SpeedUnits == SpeedUnits.CentimetersPerSecond)
{
unitsString = "centimeters per second";
}
return Amount + " " + unitsString;
}
}