avnc 018
This commit is contained in:
parent
2344912a1a
commit
f9c691c11b
@ -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 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[] 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,43 +54,126 @@ int rand_int(int[] choices) {
|
|||||||
return choices[indx];
|
return choices[indx];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < max_pets - 4; i++) {
|
void populate_animals_array() {
|
||||||
bool uniq_id = false;
|
for (int i = 0; i < max_pets - 4; i++) {
|
||||||
our_animals[i, 0] = rand_str(species);
|
bool uniq_id = false;
|
||||||
while (!uniq_id) {
|
our_animals[i, 0] = rand_str(species);
|
||||||
bool check = true;
|
while (!uniq_id) {
|
||||||
string id = $"{rand_str(abcd)}{rand_int(nums)}";
|
bool check = true;
|
||||||
for (int j = 0; j < max_pets - 4; j++) {
|
string id = $"{rand_str(abcd)}{rand_int(nums)}";
|
||||||
if (!string.IsNullOrEmpty(our_animals[j, 1]) && our_animals[j, 1] == id) {
|
for (int j = 0; j < max_pets - 4; j++) {
|
||||||
uniq_id = false;
|
if (!string.IsNullOrEmpty(our_animals[j, 1]) && our_animals[j, 1] == id) {
|
||||||
check = false;
|
uniq_id = false;
|
||||||
break;
|
check = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (check) {
|
||||||
|
our_animals[i, 1] = id;
|
||||||
|
uniq_id = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (check) {
|
our_animals[i, 2] = rand_str(description);
|
||||||
our_animals[i, 1] = id;
|
our_animals[i, 3] = $"{rand_int(nums)}";
|
||||||
uniq_id = true;
|
our_animals[i, 4] = rand_str(personality);
|
||||||
}
|
our_animals[i, 5] = rand_str(nickname);
|
||||||
}
|
|
||||||
our_animals[i, 2] = rand_str(description);
|
|
||||||
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());
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_pets();
|
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";
|
||||||
|
string desc = pet[2];
|
||||||
|
string perso = pet[4];
|
||||||
|
print($@" ID: {id} SPECIE: {specie}
|
||||||
|
NAME: {name} AGE: {age} {year_word}
|
||||||
|
DESCRIPTION: {desc}
|
||||||
|
PERSONALITY: {perso}
|
||||||
|
{separator}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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