diff --git a/018_Conditional_branching_and_looping/018_csharp.md b/018_Conditional_branching_and_looping/018_csharp.md index f3698be..122d4f2 100644 --- a/018_Conditional_branching_and_looping/018_csharp.md +++ b/018_Conditional_branching_and_looping/018_csharp.md @@ -1,4 +1,6 @@ -# Guided project - Develop conditional branching and looping structures in C# +# Guided project + +## Develop conditional branching and looping structures in C# Gain experience developing a console app that implements selection and iteration statements to achieve app specifications. @@ -183,3 +185,9 @@ can unzip the files in a sandbox or hosted environment. You're now ready to begin the Guided project exercises. Good luck! --- + +Project Files + +- [Starter](./GuidedProject/Starter/Program.cs) +- [Final](./GuidedProject/Final/Program.cs) +- [Own](./GuidedProject/Own/Program.cs) diff --git a/018_Conditional_branching_and_looping/GuidedProject/Own/Program.cs b/018_Conditional_branching_and_looping/GuidedProject/Own/Program.cs index 956ad45..abc79be 100644 --- a/018_Conditional_branching_and_looping/GuidedProject/Own/Program.cs +++ b/018_Conditional_branching_and_looping/GuidedProject/Own/Program.cs @@ -1,12 +1,25 @@ int max_pets = 8; bool exit = false; string? selection; -string separator = "+------------------------------------------" + - "--------------------------------------------+"; +string separator = "+-------------------------------------" + + "--------------------------------------+"; +string main_menu = @" + 1. List all of our current pet information. + 2. Assign values to the ourAnimals array fields. + 3. Ensure animal ages and physical descriptions are complete. + 4. Ensure animal nicknames and personality descriptions are complete. + 5. Edit an animal's age. + 6. Edit an animal's personality description. + 7. Display all cats with a specified characteristic. + 8. Display all dogs with a specified characteristic. + + Enter menu item selection or type 'Exit' to exit the program +"; string[] description = { "big sized female golden colored weighing about 20 pounds. housebroken.", "large dark-brown male siver back weighing about 15 pounds. housebroken.", "small white female weighing about 8 pounds. translucid at sun.", + "medium size male. fluorescent at night.", }; string[] personality = { "friendly", @@ -14,18 +27,6 @@ string[] personality = { "loves to have her belly rubbed. gives lots of kisses.", "sauvage and lovelly.", }; -string main_menu = @" - 1. List all of our current pet information. - 2. Assign values to the ourAnimals array fields. - 3. Ensure animal ages and physical descriptions are complete. - 4. Ensure animal nicknames and personality descriptions are complete. - 5. Edit an animal’s age. - 6. Edit an animal’s personality description. - 7. Display all cats with a specified characteristic. - 8. Display all dogs with a specified characteristic. - - Enter menu item selection or type 'Exit' to exit the program -"; string[] options = { "1", "2", "3", "4", "5", "6", "7", "8", "exit" }; string[] nickname = { "lola", "loki", "fuzz", "boby", "gogo", "besti" }; string[] species = { "cat", "dog", "bee", "pig" }; @@ -86,11 +87,12 @@ void press_enter() { } void print_pets(string[,] animals) { + clear(); print(separator); for (int j = 0; j < animals.GetLength(0); j++) { string[] animal = new string[6]; - for (int k=0; k 0) { + bool another = false; + do { + string resp = get_input("Do you want to enter info for another pet?: "); + bool invalid = true; + if (resp != "") { + while(invalid) { + switch (resp) { + case "y" or "yes": + add_new_pet(our_animals, slots); + resp = ""; + invalid = false; + another = true; + break; + case "n" or "no": + invalid = false; + another = false; + break; + default: + resp = get_input("Please enter [Y]es or [N]o: "); + break; + } + } + } + slots = availability(our_animals); + } while (another && slots > 0); + if (slots == 0) { + print("We have reached our limit on the number of pets that we can manage."); + press_enter(); + } + press_enter(); + } else { + press_enter(); + } +} + populate_animals_array(); while (!exit) { clear(); @@ -122,14 +208,11 @@ while (!exit) { selection = selection.ToLower(); switch (selection) { case "1": - clear(); print_pets(our_animals); press_enter(); break; case "2": - clear(); - print("Assign values to the ourAnimals array fields"); - press_enter(); + ask_new_pet(); break; case "3": clear(); @@ -143,12 +226,12 @@ while (!exit) { break; case "5": clear(); - print("Edit an animal’s age"); + print("Edit an animal's age"); press_enter(); break; case "6": clear(); - print("Edit an animal’s personality description"); + print("Edit an animal's personality description"); press_enter(); break; case "7": @@ -162,7 +245,7 @@ while (!exit) { press_enter(); break; case "exit": - print("\n\tFinalizando aplicación\n"); + print("\n\tTerminating application\n"); exit = !exit; break; default: