-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
277 lines (228 loc) · 9.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
using System;
// ourAnimals array will store the following:
string animalSpecies = "";
string animalID = "";
string animalAge = "";
string animalPhysicalDescription = "";
string animalPersonalityDescription = "";
string animalNickname = "";
string suggestedDonation = "";
// variables that support data entry
int maxPets = 8;
string? readResult;
string menuSelection = "";
decimal decimalDonation = 0.00m;
// array used to store runtime data
string[,] ourAnimals = new string[maxPets, 7];
// sample data ourAnimals array entries
for (int i = 0; i < maxPets; i++)
{
switch (i)
{
case 0:
animalSpecies = "dog";
animalID = "d1";
animalAge = "2";
animalPhysicalDescription = "medium sized cream colored female golden retriever weighing about 45 pounds. housebroken.";
animalPersonalityDescription = "loves to have her belly rubbed and likes to chase her tail. gives lots of kisses.";
animalNickname = "lola";
suggestedDonation = "85.00";
break;
case 1:
animalSpecies = "dog";
animalID = "d2";
animalAge = "9";
animalPhysicalDescription = "large reddish-brown male golden retriever weighing about 85 pounds. housebroken.";
animalPersonalityDescription = "loves to have his ears rubbed when he greets you at the door, or at any time! loves to lean-in and give doggy hugs.";
animalNickname = "gus";
suggestedDonation = "49.99";
break;
case 2:
animalSpecies = "cat";
animalID = "c3";
animalAge = "1";
animalPhysicalDescription = "small white female weighing about 8 pounds. litter box trained.";
animalPersonalityDescription = "friendly";
animalNickname = "snow";
suggestedDonation = "40.00";
break;
case 3:
animalSpecies = "cat";
animalID = "c4";
animalAge = "";
animalPhysicalDescription = "";
animalPersonalityDescription = "";
animalNickname = "lion";
suggestedDonation = "";
break;
default:
animalSpecies = "";
animalID = "";
animalAge = "";
animalPhysicalDescription = "";
animalPersonalityDescription = "";
animalNickname = "";
suggestedDonation = "";
break;
}
ourAnimals[i, 0] = "ID #: " + animalID;
ourAnimals[i, 1] = "Species: " + animalSpecies;
ourAnimals[i, 2] = "Age: " + animalAge;
ourAnimals[i, 3] = "Nickname: " + animalNickname;
ourAnimals[i, 4] = "Physical description: " + animalPhysicalDescription;
ourAnimals[i, 5] = "Personality: " + animalPersonalityDescription;
if (!decimal.TryParse(suggestedDonation, out decimalDonation))
{
decimalDonation = 45.00m; // if suggestedDonation NOT a number, default to 45.00
}
ourAnimals[i, 6] = $"Suggested Donation: {decimalDonation:C2}";
}
// top-level menu options
do
{
// NOTE: the Console.Clear method is throwing an exception in debug sessions
Console.Clear();
Console.WriteLine("Welcome to the Contoso PetFriends app. Your main menu options are:");
Console.WriteLine(" 1. List all of our current pet information");
Console.WriteLine(" 2. Display all dogs with a specified characteristic");
Console.WriteLine();
Console.WriteLine("Enter your selection number (or type Exit to exit the program)");
readResult = Console.ReadLine();
if (readResult != null)
{
menuSelection = readResult.ToLower();
}
// switch-case to process the selected menu option
switch (menuSelection)
{
case "1":
// list all pet info
for (int i = 0; i < maxPets; i++)
{
if (ourAnimals[i, 0] != "ID #: ")
{
Console.WriteLine();
for (int j = 0; j < 7; j++)
{
Console.WriteLine(ourAnimals[i, j].ToString());
}
}
}
Console.WriteLine("\r\nPress the Enter key to continue");
readResult = Console.ReadLine();
break;
case "2":
//define dogchar string, which will hold multiple charaterisitics !
//create a while loop that checks if dogchars is empty !
//while its empty you need this: !
// Console.WriteLine($"\nEnter dog characteristics to search for separated by commas"); !
// readResult = Console.ReadLine(); !
// to read the input !
// if the read result is not null then !
// dogchars is equal to the read result but lowercase version !
// then console writeline for empty line!
// end if and while!
//declare dogInput string set it equal to dogchars split by comma !
//for loop to trim each item in the array !
// sort dog input array !
//define icon array !
//string[] icons = {" |", " /", "--", " \\", " *"}; !
// set matched a dog to false !
// define dog desc string !
//start a large for loop that goes thru our animals array, with maxPets as length condition !
// within the for loop there is an if statement that checks if the i-th row and second (index 1) column contains "dog"!
// within the if statement we need to set dogdesc to our animals i-th row and 5th column (index 4) + "\n" + our animals i-th row 6th column (index 5)!
// define bool currentMatch equals false
// start a foreach that goes through each word in input array!
// within the foreach make an if statement that checks if word is not null and word trimmed is not empty string!
// within the if statement create a for loop with j instead of i since we are already inside a for loop that uses i
// this for loop starts at index 2 and j is greater than -1 , j--
// #5 update "searching" message to show countdown by creating a foreach!
// string icon in icons!
// within the foreach loop !
// Console.Write($"\rsearching our dog {ourAnimals[i, 3]} for {term.Trim()} {icon} {j.ToString()}");
// Thread.Sleep(100);!
// end foreach!
// Console.Write($"\r{new String(' ', Console.BufferWidth)}");!
//end j for loop!
// start if statement that iterates submitted characteristic terms and search description for each term!
// if the dog desc contains " " + word.Trim() + " "
// then
// Console.WriteLine($"\rOur dog {ourAnimals[i, 3]} matches your search for {term.Trim()}");
// matchesCurrentDog = true;!
// matchesAnyDog = true;!
//end if statement!
//end larger if statement!
// end foreach loop!
//check if matches current dog is true
// then Console.WriteLine($"\r{ourAnimals[i, 3]} ({ourAnimals[i, 0]})\n{dogDescription}\n");
// end if!
// end larger if!
// end for loop with max pets restriction!
//lastly if matches any dog is not true
// write none of our dogs are a match for + dog chars
// end if
string dogCharacteristics = "";
while (dogCharacteristics is "")
{
Console.WriteLine($"\nEnter dog characteristics to search for separated by commas");
readResult = Console.ReadLine();
if (readResult is not null)
{
dogCharacteristics = readResult.ToLower();
Console.WriteLine();
}
}
string[] dogInputArray = dogCharacteristics.Split(",");
for (int i = 0; i < dogInputArray.Length; i++)
{
dogInputArray[i] = dogInputArray[i].Trim();
}
Array.Sort(dogInputArray);
string[] icons = {" |", " /", "--", " \\", " *"}; // define icon array used for loading animation
bool matchADog = false;
string dogDescription = "";
for (int i = 0; i < maxPets; i++)
{
if (ourAnimals[i, 1].Contains("dog"))
{
dogDescription = ourAnimals[i, 4] + "\n" + ourAnimals[i, 5];
bool currentMatch = false;
foreach (string word in dogInputArray)
{
if (word is not null && word.Trim() is not "")
{
for (int j = 2; j > -1; j--)
{
foreach (string icon in icons)
{
Console.Write($"\rsearching our dog {ourAnimals[i, 3]} for {word.Trim()} {icon} {j.ToString()}");
Thread.Sleep(100);
}
Console.Write($"\r{new String(' ', Console.BufferWidth)}");
}
if (dogDescription.Contains(" " + word.Trim() + " "))
{
Console.WriteLine($"\rOur dog {ourAnimals[i, 3]} matches your search for {word.Trim()}");
currentMatch = true;
matchADog = true;
}
}
}
if (currentMatch)
{
Console.WriteLine($"\r{ourAnimals[i, 3]} ({ourAnimals[i, 0]})\n{dogDescription}\n");
}
}
}
if (!matchADog)
{
Console.Write($"None of our dogs are a match for: {dogCharacteristics}");
}
Console.WriteLine("\n\rPress the Enter key to continue");
readResult = Console.ReadLine();
break;
default:
break;
}
} while (menuSelection != "exit");