avnc 018
This commit is contained in:
parent
2344912a1a
commit
f9c691c11b
@ -1,13 +1,12 @@
|
||||
int max_pets = 8;
|
||||
//string? read_input;
|
||||
//string menu_selection = "";
|
||||
bool exit = false;
|
||||
string? selection;
|
||||
string separator = "+------------------------------------------" +
|
||||
"--------------------------------------------+";
|
||||
string[] description = {
|
||||
"medium sized cream colored female golden retriever weighing about 65" +
|
||||
"pounds. housebroken.",
|
||||
"large reddish-brown male golden retriever weighing about 85 pounds. " +
|
||||
"housebroken.",
|
||||
"small white female weighing about 8 pounds. litter box trained.",
|
||||
"translucid at sun.",
|
||||
"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.",
|
||||
};
|
||||
string[] personality = {
|
||||
"friendly",
|
||||
@ -15,14 +14,35 @@ 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" };
|
||||
string[] abcd = { "a", "b", "c", "d" };
|
||||
int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
string[,] our_animals = new string[max_pets, 6];
|
||||
Random rand = new Random();
|
||||
|
||||
// array used to store runtime data, there is no persisted data
|
||||
string[,] our_animals = new string[max_pets, 6];
|
||||
var clear = Console.Clear;
|
||||
|
||||
void print(string text, bool new_line = true) {
|
||||
if (new_line) {
|
||||
Console.WriteLine(text);
|
||||
} else {
|
||||
Console.Write(text);
|
||||
}
|
||||
}
|
||||
|
||||
string rand_str(string[] choices) {
|
||||
int indx = rand.Next(choices.Length);
|
||||
@ -34,7 +54,8 @@ int rand_int(int[] choices) {
|
||||
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;
|
||||
our_animals[i, 0] = rand_str(species);
|
||||
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, 4] = rand_str(personality);
|
||||
our_animals[i, 5] = rand_str(nickname);
|
||||
}
|
||||
}
|
||||
|
||||
void print_pets() {
|
||||
for (int j = 0; j < max_pets; j++) {
|
||||
if (!string.IsNullOrEmpty(our_animals[j, 1])) {
|
||||
Console.Write(our_animals[j, 1] + ": ");
|
||||
Console.Write(our_animals[j, 0] + " - ");
|
||||
Console.Write(our_animals[j, 5] + " - ");
|
||||
int age = Int32.Parse(our_animals[j,3].ToString());
|
||||
void press_enter() {
|
||||
print("\n\tPress 'Enter' to continue", false);
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
void print_pets(string[,] animals) {
|
||||
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";
|
||||
Console.WriteLine(our_animals[j, 3] + $" {year_word}");
|
||||
Console.WriteLine(our_animals[j, 2]);
|
||||
Console.WriteLine(our_animals[j, 4]+"\n");
|
||||
}
|
||||
string desc = pet[2];
|
||||
string perso = pet[4];
|
||||
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 animal’s age");
|
||||
press_enter();
|
||||
break;
|
||||
case "6":
|
||||
clear();
|
||||
print("Edit an animal’s 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);
|
||||
|
Loading…
Reference in New Issue
Block a user