-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuto.cs
104 lines (77 loc) · 1.77 KB
/
Auto.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UnderstandingOO
{
internal class Automobile
{
private string make;
public string Model;
public int Year;
public string Color;
public int Miles;
private int speed;
public Engine Engine;
public AutoCustomer Customer = new AutoCustomer();
public class AutoCustomer
{
public string LastName;
public string Address;
public DateTime DateOfPurchase;
}
public string Maker
{
get
{
return make;
}
set
{
make = value;
}
}
public int CurrentSpeed
{
get
{
return speed;
}
set
{
if (value < 0) speed = 0;
else if (value > 110) speed = 110;
else speed = value;
}
}
public int Accelerate(int increasedSpeed)
{
CurrentSpeed += increasedSpeed;
writeLine("Current speed: " + CurrentSpeed);
//Console.WriteLine("Current speed: " + Speed.ToString());
return CurrentSpeed;
}
public int Decelerate(int decreasedSpeed)
{
CurrentSpeed -= decreasedSpeed;
//Console.WriteLine("Current speed: " + Speed.ToString());
writeLine("Current speed: " + CurrentSpeed);
return CurrentSpeed;
}
public string SpeedLimitViolation(string initialMessage, int speedLimit)
{
string message = "";
if (CurrentSpeed > speedLimit) message = "Too fast";
else message = "You're OK";
return initialMessage + " " + message;
}
private void writeLine(string message)
{
if (message != null)
{
Console.Write("FROM MY HELPER METHOD ... ");
Console.WriteLine(message);
}
}
}
}