-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
163 lines (145 loc) · 4.46 KB
/
Copy pathProgram.cs
File metadata and controls
163 lines (145 loc) · 4.46 KB
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
// Screen Sound
//Pattern Camel Case
using System.Diagnostics;
string welcomeMsg = "Welcome to Music Box!";
// List<string> bandsList = new List<string> {"Oasis", "Shakira", "Nirvana"};
Dictionary<string, List<int>> registeredBands = new Dictionary<string, List<int>>();
registeredBands.Add("Oasis", new List<int> { 10, 8, 6 });
registeredBands.Add("Mana", new List<int>());
//Pattern Pascal Case
void DisplayLogo()
{
Console.WriteLine(@"
█▀▄▀█ █░█ █▀ █ █▀▀ █▄▄ █▀█ ▀▄▀
█░▀░█ █▄█ ▄█ █ █▄▄ █▄█ █▄█ █░█
");
}
//@"" => Verbatim Literal - display the string exactly how it will be
void DisplayMenuOptions()
{
DisplayLogo();
Console.WriteLine(welcomeMsg);
Console.WriteLine("\nWrite 1 to register a band");
Console.WriteLine("Write 2 to display all bands");
Console.WriteLine("Write 3 to rate a band");
Console.WriteLine("Write 4 to display the band average rate");
Console.WriteLine("Write -1 to leave the application");
Console.Write("\nWhat is your choice? ");
string choseOption = Console.ReadLine()!;
int choseOptionNumber = int.Parse(choseOption);
switch (choseOptionNumber)
{
case 1:
RegisterBand();
break;
case 2:
DisplayBandsList();
break;
case 3:
RateBand();
break;
case 4:
DisplayBandAverage();
break;
case -1:
Console.WriteLine("Bye bye :)");
break;
default:
Console.WriteLine("Invalid option");
break;
}
}
void RegisterBand()
{
Console.Clear();
DisplayLogo();
DisplayTitle("Register a band");
Console.Write("\nWrite the band name: ");
string bandName = Console.ReadLine()!;
registeredBands.Add(bandName, new List<int>());
Console.WriteLine($"The band {bandName} was successfully registered!");
Thread.Sleep(2000);
Console.Clear();
DisplayMenuOptions();
}
void DisplayBandsList()
{
Console.Clear();
DisplayLogo();
DisplayTitle("Check all bands");
//for with integer
// for (int i = 0; i < bandsList.Count(); i++)
// {
// Console.WriteLine($"Band => {bandsList[i]}");
// }
foreach (string band in registeredBands.Keys)
{
Console.WriteLine($"Band => {band}");
}
Console.WriteLine("\nWrite a key to return to the menu");
Console.ReadKey();
Console.Clear();
DisplayMenuOptions();
}
void DisplayTitle(string title)
{
int lettersQuantity = title.Length;
string asterisks = string.Empty.PadLeft(lettersQuantity, '*');
Console.WriteLine(asterisks);
Console.WriteLine(title);
Console.WriteLine(asterisks + "\n");
}
void RateBand()
{
//which band?
//if band exist -> add rate
//otherwise return menu
Console.Clear();
DisplayLogo();
DisplayTitle("Rate a band");
Console.Write("Write the band name you want to rate: ");
string bandName = Console.ReadLine()!;
if (registeredBands.ContainsKey(bandName))
{
Console.Write($"\nWhich rate the band #{bandName} deserve? ");
int rate = int.Parse(Console.ReadLine()!);
registeredBands[bandName].Add(rate);
Console.WriteLine($"\nThe rate => {rate} was successfully registered to #{bandName}!");
Thread.Sleep(4000);
Console.Clear();
DisplayMenuOptions();
}
else
{
Console.WriteLine($"\nThe band => {bandName} was not found");
Console.WriteLine("Press any key to return to menu");
Console.ReadKey();
Console.Clear();
DisplayMenuOptions();
}
}
void DisplayBandAverage()
{
Console.Clear();
DisplayLogo();
DisplayTitle("Check the bands average rate");
Console.Write("\nWhich band average do you want to know? ");
string bandName = Console.ReadLine()!;
if (registeredBands.ContainsKey(bandName))
{
double bandAverage = registeredBands["Oasis"].Average();
Console.WriteLine($"\nThe band #{bandName} average is => {bandAverage}!");
Thread.Sleep(4000);
Console.Clear();
DisplayMenuOptions();
}
else
{
Console.WriteLine($"The band #{bandName} was not found");
Console.WriteLine("\nPress any key to return to menu");
Console.ReadKey();
Console.Clear();
DisplayMenuOptions();
}
}
DisplayMenuOptions();