-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
447 lines (383 loc) · 17.2 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/*======================================================*/
/*======================================================*/
/*======================================================*/
/*CONTOSO PETS APPLICATION*/
// the ourAnimals array will store the following:
string animalSpecies = "";
string animalID = "";
string animalAge = "";
string animalPhysicalDescription = "";
string animalPersonalityDescription = "";
string animalNickname = "";
// variables that support data entry
int maxPets = 8;
string? readResult;
string menuSelection = "";
// array used to store runtime data, there is no persisted data
string[,] ourAnimals = new string[maxPets, 6];
// TODO: Convert the if-elseif-else construct to a switch statement
// create some initial 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 65 pounds. housebroken.";
animalPersonalityDescription = "loves to have her belly rubbed and likes to chase her tail. gives lots of kisses.";
animalNickname = "lola";
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 = "loki";
break;
case 2:
animalSpecies = "cat";
animalID = "c3";
animalAge = "1";
animalPhysicalDescription = "small white female weighing about 8 pounds. litter box trained.";
animalPersonalityDescription = "friendly";
animalNickname = "Puss";
break;
case 3:
animalSpecies = "cat";
animalID = "c4";
animalAge = "?";
animalPhysicalDescription = "tbd";
animalPersonalityDescription = "tbd";
animalNickname = "tbd";
break;
default:
animalSpecies = "";
animalID = "";
animalAge = "";
animalPhysicalDescription = "";
animalPersonalityDescription = "";
animalNickname = "";
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;
}
// display the top-level menu options
do
{
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. Add a new animal friend to the ourAnimals array");
Console.WriteLine(" 3. Ensure animal ages and physical descriptions are complete");
Console.WriteLine(" 4. Ensure animal nicknames and personality descriptions are complete");
Console.WriteLine(" 5. Edit an animal’1s age");
Console.WriteLine(" 6. Edit an animal’s personality description");
Console.WriteLine(" 7. Display all cats with a specified characteristic");
Console.WriteLine(" 8. 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();
}
// Console.WriteLine($"You selected menu option {menuSelection}.");
// Console.WriteLine("Press the Enter key to continue");
// // pause code execution
// readResult = Console.ReadLine();
switch(menuSelection)
{
case "1":
// List all of our current pet information
for ( int i = 0; i < maxPets; i++)
{
if (ourAnimals[i,0] != "ID #: ")
{
for(int j = 0; j < 6; j++)
{
Console.WriteLine(ourAnimals[i,j]);
}
}
}
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
break;
case "2":
// Add a new animal friend to the ourAnimals array
string anotherPet = "y";
int petCount = 0;
for (int i = 0; i < maxPets; i++)
{
if(ourAnimals[i, 0] != "ID #: ")
{
petCount += 1;
}
}
if (petCount < maxPets)
{
Console.WriteLine($"We currently have {petCount} pets that need homes. We can manage {(maxPets - petCount)} more.");
}
bool validEntry = false;
// get species (cat or dog) - string animalSpecies is a required field
do
{
Console.WriteLine("\n\rEnter 'dog' or 'cat' to begin a new entry.");
readResult = Console.ReadLine();
if(readResult != null)
{
animalSpecies = readResult.ToLower();
if (animalSpecies != "dog" && animalSpecies != "cat")
{
validEntry = false;
//Console.WriteLine($"You entered: {animalSpecies}.");
}
else
{
validEntry = true;
}
}
}while(validEntry == false);
// build the animal the ID number - for example C1, C2, D3 (for Cat 1, Cat 2, Dog 3)
animalID = animalSpecies.Substring(0,1) + (petCount + 1).ToString();
// get the pet's age. can be ? at initial entry.
do
{
int petAge;
Console.WriteLine("Enter the pet's age or enter ? if unkown");
readResult = Console.ReadLine();
if (readResult != null)
{
animalAge = readResult;
if (animalAge != "?")
{
validEntry = int.TryParse(animalAge, out petAge);
}
}
} while (validEntry == false);
// get a description of the pet's physical appearance/condition - animalPhysicalDescription can be blank.
do
{
Console.WriteLine("Enter a physical description of the pet (size, color, gender, weight, housebroken)");
readResult = Console.ReadLine();
if (readResult != null)
{
animalPhysicalDescription = readResult.ToLower();
if (animalPhysicalDescription == "")
{
animalPhysicalDescription = "tbd";
}
}
} while (animalPhysicalDescription == "");
// get a description of the pet's personality - animalPersonalityDescription can be blank.
do
{
Console.WriteLine("Enter a description of the pet's personality (likes or dislikes, tricks, energy level)");
readResult = Console.ReadLine();
if (readResult != null)
{
animalPersonalityDescription = readResult.ToLower();
if (animalPersonalityDescription == "")
{
animalPersonalityDescription = "tbd";
}
}
} while (animalPersonalityDescription == "");
// get the pet's nickname. animalNickname can be blank.
do
{
Console.WriteLine("Enter a nickname for the pet");
readResult = Console.ReadLine();
if (readResult != null)
{
animalNickname = readResult.ToLower();
if (animalNickname == "")
{
animalNickname = "tbd";
}
}
} while (animalNickname == "");
// store the pet information in the ourAnimals array (zero based)
ourAnimals[petCount, 0] = "ID #: " + animalID;
ourAnimals[petCount, 1] = "Species: " + animalSpecies;
ourAnimals[petCount, 2] = "Age: " + animalAge;
ourAnimals[petCount, 3] = "Nickname: " + animalNickname;
ourAnimals[petCount, 4] = "Physical description: " + animalPhysicalDescription;
ourAnimals[petCount, 5] = "Personality: " + animalPersonalityDescription;
while (anotherPet =="y" && petCount < maxPets)
{
// increment petCount (the array is zero-based, so we increment the counter after adding to the array)
petCount += 1;
// check maxPet limit
if (petCount < maxPets)
{
// another pet?
Console.WriteLine("Do you want to enter info for another pet (y/n)");
do
{
readResult = Console.ReadLine();
if (readResult != null)
{
anotherPet = readResult.ToLower();
}
}while (anotherPet != "y" && anotherPet != "n");
}
}
if (petCount >= maxPets)
{
Console.WriteLine("We have reached our limit on the number of pets that we can manage.");
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
}
break;
case "3":
for (int i = 0; i < maxPets; i++)
{
// check if animal's age info has been added
while (ourAnimals[i, 0] != "ID #: " && ourAnimals[i,2] == "Age: ?")
{
//prompt user to input age for the specific pet without age defined
Console.WriteLine($"Enter an age for {ourAnimals[i,0]}");
validEntry = false;
do
{
int petAge;
// recieve user's input for Pet's age
Console.WriteLine("Enter numeric values for the Animal's age, in integer format such as 1,2,3... and so on");
readResult = Console.ReadLine();
if(readResult != null)
{
animalAge = readResult;
if(animalAge != "?")
{
// Enforce the following validation rules for animalAge
validEntry = int.TryParse(animalAge, out petAge);
ourAnimals[i, 2] = "Age: " + petAge;
}
else
{
validEntry = false;
}
}
}while(validEntry == false);
}
// check if animal's physical desciption info has been added
while (ourAnimals[i, 0] != "ID #: " && ourAnimals[i,4] == "Physical description: tbd" )
{
validEntry = false;
do
{
// recieve user's input for Pet's physical desciption
Console.WriteLine($"Enter a physical description for {ourAnimals[i,0]} (size, color, breed, gender, weight, housebroken)");
readResult = Console.ReadLine();
if(readResult != null)
{
animalPhysicalDescription = readResult;
if(animalPhysicalDescription != "")
{
// Enforce the following validation rules for Pet's physical desciption
validEntry = true;
ourAnimals[i, 4] = "Physical description: " + animalPhysicalDescription;
}
else
{
validEntry = false;
}
}
}while(validEntry == false);
}
}
Console.WriteLine("Age and physical description fields are complete for all of our friends.");
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
break;
case "4":
for (int i = 0; i < maxPets; i++)
{
// check if animal's nickname info has been added
while (ourAnimals[i, 0] != "ID #: " && ourAnimals[i,3] == "Nickname: tbd")
{
validEntry = false;
do
{
// recieve user's input for Pet's nickname
Console.WriteLine($"Enter a nickname for {ourAnimals[i,0]}");
readResult = Console.ReadLine();
if(readResult != null)
{
animalNickname = readResult;
if(animalNickname != "")
{
// Enforce the following validation rules for Pet's nickname
validEntry = true;
ourAnimals[i, 3] = "Nickname: " + animalNickname;
}
else
{
validEntry = false;
}
}
}while(validEntry == false);
}
// check if animal's personality info has been added
while (ourAnimals[i, 0] != "ID #: " && ourAnimals[i,5] == "Personality: tbd" )
{
validEntry = false;
do
{
// recieve user's input for Pet's personality
Console.WriteLine($"Enter a personality description for {ourAnimals[i,0]} (likes or dislikes, tricks, energy level)");
readResult = Console.ReadLine();
if(readResult != null)
{
animalPersonalityDescription = readResult;
if(animalPersonalityDescription != "")
{
// Enforce the following validation rules for Pet's personality
validEntry = true;
ourAnimals[i, 5] = "Personality: " + animalPersonalityDescription;
}
else
{
validEntry = false;
}
}
}while(validEntry == false);
}
}
Console.WriteLine("Nickname and personality description fields are complete for all of our friends.");
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
break;
case "5":
Console.WriteLine("UNDER CONSTRUCTION - please check back next month to see progress.");
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
break;
case "6":
Console.WriteLine("UNDER CONSTRUCTION - please check back next month to see progress.");
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
break;
case "7":
Console.WriteLine("UNDER CONSTRUCTION - please check back next month to see progress.");
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
break;
case "8":
Console.WriteLine("UNDER CONSTRUCTION - please check back next month to see progress.");
Console.WriteLine("Press the Enter key to continue.");
readResult = Console.ReadLine();
break;
default:
Console.WriteLine("Press the Enter key to continue");
break;
}
} while (menuSelection != "exit");