This commit is contained in:
ipvg 2024-07-24 00:47:40 -04:00
parent 2344912a1a
commit f9c691c11b

View File

@ -1,13 +1,12 @@
int max_pets = 8; int max_pets = 8;
//string? read_input; bool exit = false;
//string menu_selection = ""; string? selection;
string separator = "+------------------------------------------" +
"--------------------------------------------+";
string[] description = { string[] description = {
"medium sized cream colored female golden retriever weighing about 65" + "big sized female golden colored weighing about 20 pounds. housebroken.",
"pounds. housebroken.", "large dark-brown male siver back weighing about 15 pounds. housebroken.",
"large reddish-brown male golden retriever weighing about 85 pounds. " + "small white female weighing about 8 pounds. translucid at sun.",
"housebroken.",
"small white female weighing about 8 pounds. litter box trained.",
"translucid at sun.",
}; };
string[] personality = { string[] personality = {
"friendly", "friendly",
@ -15,14 +14,35 @@ string[] personality = {
"loves to have her belly rubbed. gives lots of kisses.", "loves to have her belly rubbed. gives lots of kisses.",
"sauvage and lovelly.", "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 animals age.
6. Edit an animals 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[] nickname = { "lola", "loki", "fuzz", "boby", "gogo", "besti" };
string[] species = { "cat", "dog", "bee", "pig" }; string[] species = { "cat", "dog", "bee", "pig" };
string[] abcd = { "a", "b", "c", "d" }; string[] abcd = { "a", "b", "c", "d" };
int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8 }; int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8 };
string[,] our_animals = new string[max_pets, 6];
Random rand = new Random(); Random rand = new Random();
// array used to store runtime data, there is no persisted data var clear = Console.Clear;
string[,] our_animals = new string[max_pets, 6];
void print(string text, bool new_line = true) {
if (new_line) {
Console.WriteLine(text);
} else {
Console.Write(text);
}
}
string rand_str(string[] choices) { string rand_str(string[] choices) {
int indx = rand.Next(choices.Length); int indx = rand.Next(choices.Length);
@ -34,7 +54,8 @@ int rand_int(int[] choices) {
return choices[indx]; return choices[indx];
} }
for (int i = 0; i < max_pets - 4; i++) { void populate_animals_array() {
for (int i = 0; i < max_pets - 4; i++) {
bool uniq_id = false; bool uniq_id = false;
our_animals[i, 0] = rand_str(species); our_animals[i, 0] = rand_str(species);
while (!uniq_id) { while (!uniq_id) {
@ -56,21 +77,103 @@ for (int i = 0; i < max_pets - 4; i++) {
our_animals[i, 3] = $"{rand_int(nums)}"; our_animals[i, 3] = $"{rand_int(nums)}";
our_animals[i, 4] = rand_str(personality); our_animals[i, 4] = rand_str(personality);
our_animals[i, 5] = rand_str(nickname); our_animals[i, 5] = rand_str(nickname);
}
} }
void print_pets() { void press_enter() {
for (int j = 0; j < max_pets; j++) { print("\n\tPress 'Enter' to continue", false);
if (!string.IsNullOrEmpty(our_animals[j, 1])) { Console.ReadLine();
Console.Write(our_animals[j, 1] + ": "); }
Console.Write(our_animals[j, 0] + " - ");
Console.Write(our_animals[j, 5] + " - "); void print_pets(string[,] animals) {
int age = Int32.Parse(our_animals[j,3].ToString()); print(separator);
for (int j = 0; j < animals.GetLength(0); j++) {
string[] animal = new string[6];
for (int k=0; k<animals.GetLength(1); k++) {
animal[k] = animals[j,k];
}
print_pet(animal);
}
}
void print_pet(string[] pet) {
if (!string.IsNullOrEmpty(pet[1])) {
string id = pet[1];
string name = pet[5];
string specie = pet[0];
int age = Int32.Parse(pet[3].ToString());
string year_word = age > 1 ? "years" : "year"; string year_word = age > 1 ? "years" : "year";
Console.WriteLine(our_animals[j, 3] + $" {year_word}"); string desc = pet[2];
Console.WriteLine(our_animals[j, 2]); string perso = pet[4];
Console.WriteLine(our_animals[j, 4]+"\n"); print($@" ID: {id} SPECIE: {specie}
} NAME: {name} AGE: {age} {year_word}
DESCRIPTION: {desc}
PERSONALITY: {perso}
{separator}");
} }
} }
print_pets(); populate_animals_array();
while (!exit) {
clear();
print(main_menu);
selection = Console.ReadLine();
if (selection != null && options.Contains(selection.ToLower())) {
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();
break;
case "3":
clear();
print("Ensure animal ages and physical descriptions are complete");
press_enter();
break;
case "4":
clear();
print("Ensure animal nicknames and personality descriptions are complete");
press_enter();
break;
case "5":
clear();
print("Edit an animals age");
press_enter();
break;
case "6":
clear();
print("Edit an animals personality description");
press_enter();
break;
case "7":
clear();
print("Display all cats with a specified characteristic");
press_enter();
break;
case "8":
clear();
print("Display all dogs with a specified characteristic");
press_enter();
break;
case "exit":
print("\n\tFinalizando aplicación\n");
exit = !exit;
break;
default:
print("\n\tPlease read the instructions");
press_enter();
break;
}
} else {
print("\n\tPlease read the instructions");
press_enter();
}
}
Environment.Exit(0);