-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cs
56 lines (48 loc) · 1.66 KB
/
Utilities.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
namespace ParkingDeluxe;
public static class Utilities
{
internal static Vehicle GetRandomVehicle()
{
int vehicleType = Random.Shared.Next(3);
return vehicleType switch
{
0 => GetRandomMC(),
1 => GetRandomCar(),
2 => GetRandomBus(),
_ => throw new InvalidOperationException("Unexpected vehicle type"),
};
}
private static Bus GetRandomBus()
{
int passengers = Random.Shared.Next(3, 10) * 2;
return new Bus(RegistrationNumber.GetRandom(), GetRandomColor(), passengers);
}
private static Car GetRandomCar()
{
bool isElectric = Random.Shared.Next(0, 2) > 0;
return new Car(RegistrationNumber.GetRandom(), GetRandomColor(), isElectric);
}
private static MC GetRandomMC()
{
return new MC(RegistrationNumber.GetRandom(), GetRandomColor(), GetRandomMcBrand());
}
private static string GetRandomColor()
{
string[] colors = Colors.AvailableColors;
return colors[Random.Shared.Next(colors.Length)];
}
private static string GetRandomMcBrand()
{
string[] mcBrands = McBrands.AvailableBrands;
return mcBrands[Random.Shared.Next(mcBrands.Length)];
}
public static Vehicle CheckoutRandomVehicle(ParkingSpace parking)
{
int randomIndex = Random.Shared.Next(parking.ParkedVehicles.Count);
return parking.ParkedVehicles.ElementAt(randomIndex).Value;
}
public static int GetElapsedMinutes(this ITimed timedObject) // an extension method, det är väl nice
{
return (int)Math.Ceiling(timedObject.ElapsedTime().TotalMinutes);
}
}