end 019 - pend: validate specie
This commit is contained in:
parent
0a1b0dc467
commit
3c751c6a2f
@ -9,9 +9,9 @@ iteration statements to achieve app specifications.
|
||||
|
||||
In this module, you'll demonstrate your ability to:
|
||||
|
||||
- Use Visual Studio Code to develop a C# console application that uses a
|
||||
combination of selection and iteration statements to implement logical
|
||||
workflows in accordance with supplied application data and user interactions.
|
||||
- Develop a C# console application that uses a combination of selection and
|
||||
iteration statements to implement logical workflows in accordance with supplied
|
||||
application data and user interactions.
|
||||
- Evaluate the underlying conditions and make an informed decision when
|
||||
choosing between if-elseif-else and switch statements, and between foreach,
|
||||
for, while, and do iteration statements.
|
||||
|
@ -1,9 +1,11 @@
|
||||
int max_pets = 8;
|
||||
bool exit = false;
|
||||
string? selection;
|
||||
string separator = "+-------------------------------------" +
|
||||
const string WIP = "Under Construction - please check " +
|
||||
"back next month to see progress.";
|
||||
const string separator = "+-------------------------------------" +
|
||||
"--------------------------------------+";
|
||||
string main_menu = @"
|
||||
const 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.
|
||||
@ -16,9 +18,9 @@ string main_menu = @"
|
||||
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.",
|
||||
"big sized female golden colored weighing 20 pounds. housebroken.",
|
||||
"large dark-brown male siver back weighing 15 pounds. housebroken.",
|
||||
"small white female weighing about 8 pounds. translucid.",
|
||||
"medium size male. fluorescent at night.",
|
||||
};
|
||||
string[] personality = {
|
||||
@ -29,7 +31,7 @@ string[] personality = {
|
||||
};
|
||||
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" };
|
||||
string[] species = { "cat", "dog", "bee", "pig", "fly", "rat", "bat" };
|
||||
string[] abcd = { "a", "b", "c", "d" };
|
||||
int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
string[,] our_animals = new string[max_pets, 6];
|
||||
@ -55,25 +57,32 @@ int rand_int(int[] choices) {
|
||||
return choices[indx];
|
||||
}
|
||||
|
||||
void populate_animals_array() {
|
||||
string get_uniq_id(string[,] animals) {
|
||||
for (int i = 0; i < max_pets - 4; i++) {
|
||||
bool uniq_id = false;
|
||||
our_animals[i, 0] = rand_str(species);
|
||||
while (!uniq_id) {
|
||||
bool check = true;
|
||||
string id = $"{rand_str(abcd)}{rand_int(nums)}";
|
||||
for (int j = 0; j < max_pets - 4; j++) {
|
||||
if (!string.IsNullOrEmpty(our_animals[j, 1]) && our_animals[j, 1] == id) {
|
||||
if (!string.IsNullOrEmpty(animals[j, 1]) && animals[j, 1] == id) {
|
||||
uniq_id = false;
|
||||
check = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (check) {
|
||||
our_animals[i, 1] = id;
|
||||
uniq_id = true;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
void populate_animals_array() {
|
||||
for (int i = 0; i < max_pets - 4; i++) {
|
||||
our_animals[i, 0] = rand_str(species);
|
||||
our_animals[i, 1] = get_uniq_id(our_animals);
|
||||
our_animals[i, 2] = rand_str(description);
|
||||
our_animals[i, 3] = $"{rand_int(nums)}";
|
||||
our_animals[i, 4] = rand_str(personality);
|
||||
@ -81,8 +90,8 @@ void populate_animals_array() {
|
||||
}
|
||||
}
|
||||
|
||||
void press_enter() {
|
||||
print("\n\tPress 'Enter' to continue", false);
|
||||
void press_enter(string msg = "\n\tPress 'Enter' to continue") {
|
||||
print(msg, false);
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
@ -96,6 +105,7 @@ void print_pets(string[,] animals) {
|
||||
}
|
||||
print_pet(animal);
|
||||
}
|
||||
press_enter();
|
||||
}
|
||||
|
||||
void print_pet(string[] pet) {
|
||||
@ -136,7 +146,6 @@ string get_input(string text = "Please enter your text: ", bool integer = false)
|
||||
string resp = usr_in.Trim();
|
||||
int temp_int;
|
||||
if (int.TryParse(resp, out temp_int)) {
|
||||
print($"Opción 1: {temp_int}");
|
||||
return resp;
|
||||
}
|
||||
} else {
|
||||
@ -144,7 +153,7 @@ string get_input(string text = "Please enter your text: ", bool integer = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return "?";
|
||||
}
|
||||
|
||||
void add_new_pet(string[,] animals, int slots) {
|
||||
@ -155,8 +164,6 @@ void add_new_pet(string[,] animals, int slots) {
|
||||
int age = Int32.Parse(get_input("Enter pet age (-1 if unknown): ", true));
|
||||
string desc = get_input("Enter the physical description (? if unknown): ");
|
||||
string perso = get_input("Enter pet personality (? if unknown): ");
|
||||
//print($"Will be added at index: {at_indx}");
|
||||
//print($"{id}\n{specie}\n{name}\n{age}\n{desc}\n{perso}");
|
||||
animals[at_indx, 0] = specie;
|
||||
animals[at_indx, 1] = id;
|
||||
animals[at_indx, 2] = desc;
|
||||
@ -200,19 +207,87 @@ void ask_new_pet() {
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
void check_age_and_desc() {
|
||||
int pet_count = max_pets - (availability(our_animals));
|
||||
void check_age_and_desc(string[,] animals) {
|
||||
clear();
|
||||
print("\nEnsure animal ages and physical descriptions are complete");
|
||||
int pet_count = max_pets - (availability(animals));
|
||||
for (int j = 0; j < pet_count; j++) {
|
||||
if (animals[j, 3] == "-1") {
|
||||
print("\n"+separator);
|
||||
string[] animal = {
|
||||
animals[j,0], animals[j,1], animals[j,2],
|
||||
animals[j,3], animals[j,4], animals[j,5]
|
||||
};
|
||||
print_pet(animal);
|
||||
int age = Int32.Parse(
|
||||
get_input(
|
||||
$"Enter an age for ID: {animals[j,1]}" +
|
||||
" (-1 if unknown): ", true
|
||||
)
|
||||
);
|
||||
animals[j, 3] = age.ToString();
|
||||
}
|
||||
if (animals[j, 2] == "?") {
|
||||
print("\n"+separator);
|
||||
string[] animal = {
|
||||
animals[j,0], animals[j,1], animals[j,2],
|
||||
animals[j,3], animals[j,4], animals[j,5]
|
||||
};
|
||||
print_pet(animal);
|
||||
string desc = get_input(
|
||||
$"Enter a physical description for ID: {animals[j,1]}" +
|
||||
" (? if unknown): "
|
||||
);
|
||||
animals[j, 2] = desc;
|
||||
}
|
||||
}
|
||||
press_enter();
|
||||
}
|
||||
|
||||
void check_nick_and_perso(string[,] animals) {
|
||||
clear();
|
||||
print("Ensure animal nicknames and personality descriptions are complete");
|
||||
print(separator);
|
||||
int pet_count = max_pets - (availability(animals));
|
||||
for (int j = 0; j < pet_count; j++) {
|
||||
if (animals[j, 5] == "?") {
|
||||
print("\n"+separator);
|
||||
string[] animal = {
|
||||
animals[j,0], animals[j,1], animals[j,2],
|
||||
animals[j,3], animals[j,4], animals[j,5]
|
||||
};
|
||||
print_pet(animal);
|
||||
string nick = get_input(
|
||||
$"Enter a nickname for ID: {animals[j,1]}" +
|
||||
"(? if unknown): "
|
||||
);
|
||||
animals[j, 5] = nick;
|
||||
}
|
||||
if (animals[j, 4] == "?") {
|
||||
print("\n"+separator);
|
||||
string[] animal = {
|
||||
animals[j,0], animals[j,1], animals[j,2],
|
||||
animals[j,3], animals[j,4], animals[j,5]
|
||||
};
|
||||
print_pet(animal);
|
||||
string perso = get_input(
|
||||
$"Enter a personality description for ID: {animals[j,1]}" +
|
||||
"(? if unknown): "
|
||||
);
|
||||
animals[j, 4] = perso;
|
||||
}
|
||||
}
|
||||
press_enter();
|
||||
}
|
||||
|
||||
|
||||
populate_animals_array();
|
||||
|
||||
while (!exit) {
|
||||
clear();
|
||||
print(main_menu);
|
||||
@ -222,40 +297,34 @@ while (!exit) {
|
||||
switch (selection) {
|
||||
case "1":
|
||||
print_pets(our_animals);
|
||||
press_enter();
|
||||
break;
|
||||
case "2":
|
||||
ask_new_pet();
|
||||
break;
|
||||
case "3":
|
||||
clear();
|
||||
print("Ensure animal ages and physical descriptions are complete");
|
||||
check_age_and_desc();
|
||||
press_enter();
|
||||
check_age_and_desc(our_animals);
|
||||
break;
|
||||
case "4":
|
||||
clear();
|
||||
print("Ensure animal nicknames and personality descriptions are complete");
|
||||
press_enter();
|
||||
check_nick_and_perso(our_animals);
|
||||
break;
|
||||
case "5":
|
||||
clear();
|
||||
print("Edit an animal's age");
|
||||
print(WIP);
|
||||
press_enter();
|
||||
break;
|
||||
case "6":
|
||||
clear();
|
||||
print("Edit an animal's personality description");
|
||||
print(WIP);
|
||||
press_enter();
|
||||
break;
|
||||
case "7":
|
||||
clear();
|
||||
print("Display all cats with a specified characteristic");
|
||||
print(WIP);
|
||||
press_enter();
|
||||
break;
|
||||
case "8":
|
||||
clear();
|
||||
print("Display all dogs with a specified characteristic");
|
||||
print(WIP);
|
||||
press_enter();
|
||||
break;
|
||||
case "exit":
|
||||
|
@ -22,3 +22,5 @@ Following
|
||||
- [switch case construct](./015_switch_case/015_csharp.md)
|
||||
- [FizzBuzz Challenge](./016_Iterate_using_for_statement/016_csharp.md)
|
||||
- [Looping logic using the do-while and while](./017_Looping_logic_using_do-while_and_while/017_csharp.md)
|
||||
- [Conditional branching and looping](./018_Conditional_branching_and_looping/018_csharp.md)
|
||||
- [Branching and looping structures](./019_branching_and_looping_structures/019_csharp.md)
|
||||
|
Loading…
Reference in New Issue
Block a user