-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
188 lines (164 loc) · 5.72 KB
/
Program.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
namespace zhukobeep;
internal class Program
{
class Car
{
private string Brand { get; set; }
private int Horses { get; set; }
private int YearMade { get; set; }
public Car(string brand, int horses, int yearmade)
{
Brand = brand;
Horses = horses;
YearMade = yearmade;
}
public override string ToString() =>
$"{Brand} {Horses} л.c, {YearMade} года сборки";
}
class PassengerCar : Car
{
private int Passengers { get; set; }
private Dictionary<string, int> _repairBook;
public PassengerCar(string brand, int horses, int yearmade, int passengers) : base(brand, horses, yearmade)
{
Passengers = passengers;
_repairBook = new Dictionary<string, int>();
}
public void AddRepair(string part, int year)
{
_repairBook[part] = year;
}
public int GetRepairYear(string part) =>
_repairBook.ContainsKey(part)
? _repairBook[part]
: -1;
public void PrintRepairBook()
{
if (_repairBook.Count == 0)
Console.WriteLine("Замен не производилось.");
else
{
Console.WriteLine("Ремонтная книжка: ");
foreach (KeyValuePair<string, int> partyear in _repairBook)
Console.WriteLine($"\tЧасть {partyear.Key} заменялась в {partyear.Value} году;");
}
}
public override string ToString() =>
$"{base.ToString()}, вместительностью {Passengers} чел.";
}
class Truck : Car
{
private int HowManyHotLoads { get; set; }
private string DriverName { get; set; }
private Dictionary<string, int> _cargo;
public Truck(
string brand,
int horses,
int yearmade,
int howManyHotLoads,
string driverName
) : base(brand, horses, yearmade)
{
HowManyHotLoads = howManyHotLoads;
DriverName = driverName;
_cargo = new Dictionary<string, int>();
}
public void SwitchDriver(string driverName)
{
DriverName = driverName;
}
public int AddHotLoads(string load, int wgt)
{
if (HowManyHotLoads < _cargo.Values.Sum() + wgt) return -1;
if (_cargo.ContainsKey(load))
_cargo[load] += wgt;
else
_cargo.Add(load, wgt);
return 1;
}
public int WipeHotLoads(string load, int wgt)
{
if (!_cargo.ContainsKey(load)) return -1;
if (_cargo[load] > wgt)
return -1;
if (_cargo[load] == wgt)
_cargo.Remove(load);
else
_cargo[load] -= wgt;
return 1;
}
public void PrintCargo()
{
if (_cargo.Count == 0)
Console.WriteLine("Груза нет.");
else
{
Console.WriteLine("Груз: ");
foreach (KeyValuePair<string, int> loadwgt in _cargo)
Console.WriteLine($"\t{loadwgt.Key} весом {loadwgt.Value} ед.;");
}
}
public override string ToString() =>
$"{base.ToString()}, грузоподъёмность {HowManyHotLoads} ед., за рулём {DriverName}.";
}
class Autopark
{
private string Name { get; set; }
private Dictionary<string, Car> CarPark { get; set; }
public Autopark(string name)
{
Name = name;
CarPark = new Dictionary<string, Car>();
}
public int AddCar(string id, Car car)
{
if (CarPark.ContainsKey(id)) return -1;
CarPark[id] = car;
return 1;
}
public int RemoveCar(string id)
{
if (!CarPark.ContainsKey(id)) return -1;
CarPark.Remove(id);
return 1;
}
public override string ToString()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine($"Автопарк \"{Name}\":");
if (CarPark.Count == 0)
sb.AppendLine("\tНет машин.");
else
foreach (KeyValuePair<string, Car> idcar in CarPark)
sb.AppendLine($"\tID: {idcar.Key}; Машина: {idcar.Value}");
return sb.ToString();
}
}
public static void Main(string[] args)
{
Autopark ap = new Autopark("WASP");
Car c1 = new Car("Chevvy Vintage", 69420, 1337);
Truck c2 = new Truck("MAN", 5000, 2022, 10000, "Joe Biden");
PassengerCar c3 = new PassengerCar("Volkswagen", 1400, 2003, 4);
ap.AddCar("H148YO", c1);
ap.AddCar("K228EK", c2);
ap.AddCar("A777YE", c3);
Console.Write($"Добро пожаловать в наш автопарк \"WASP\"!\n{ap}");
//TODO: Интерактивность
// int choice = 0;
// while (true)
// {
// Console.Write("Вы даёте строку: ");
// string? input = Console.ReadLine();
// if (input == null)
// {
// Console.Write("\x1B[1F\x1B[2K");
// continue;
// }
//
// input;
//
// break;
// }
}
}