-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAnimal.cs
204 lines (187 loc) · 7.47 KB
/
Animal.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
namespace AnimalShelter_Conditional_branching_and_looping
{
enum Species
{
Dog,
Cat
}
internal class Animal
{
public int Id { get; private set; }
public Species Species { get; private set; }
public int Age { get; set; }
public string CharacteristicDescription { get; private set; }
public string PersonalityDescription { get; set; }
public string Nickname { get; set; }
public void EditAge(int newAge)
{
Age = newAge;
}
public void EditPersonalityDescription(string newPersonalityDescription)
{
PersonalityDescription = newPersonalityDescription;
}
public Animal()
{
Menu();
}
public Animal(int id, Species species, int age, string characteristicDescription, string personalityDescription, string nickname)
{
Id = id;
Species = species;
Age = age;
CharacteristicDescription = characteristicDescription;
PersonalityDescription = personalityDescription;
Nickname = nickname;
}
public void Menu()
{
Console.WriteLine("Welcome to the Contoso PetFriends app. Your main menu options are:");
Console.WriteLine(" 1. List all of our current pet information");
Console.WriteLine(" 2. Add a new animal friend");
Console.WriteLine(" 3. Ensure animal ages and physical descriptions are complete");
Console.WriteLine(" 4. Ensure animal nicknames and personality descriptions are complete");
Console.WriteLine(" 5. Edit an animal’s age");
Console.WriteLine(" 6. Edit an animal’s personality description");
Console.WriteLine(" 7. Display all cats with a specified characteristic");
Console.WriteLine(" 8. Display all dogs with a specified characteristic");
Console.WriteLine(" 0. Exit the program");
int selection;
do
{
Console.Write("Enter your selection number: ");
if (int.TryParse(Console.ReadLine(), out selection))
{
ProcessSelection(selection);
}
else
{
Console.WriteLine("Invalid selection. Please enter a valid number.");
}
} while (selection != 0);
}
private void ProcessSelection(int selection)
{
switch (selection)
{
case 1:
Data.DisplayAllAnimals();
break;
case 2:
AddAnimal();
break;
case 3:
EnsureCharacteristicsComplete("age", "personalityDescription");
break;
case 4:
EnsureCharacteristicsComplete("nickname", "personalityDescription");
break;
case 5:
EditAnimalAge();
break;
case 6:
EditAnimalPersonalityDescription();
break;
case 7:
DisplayAnimalsWithSpecificCharacteristics(Species.Cat);
break;
case 8:
DisplayAnimalsWithSpecificCharacteristics(Species.Dog);
break;
case 0:
Console.WriteLine("Exiting the program. Goodbye!");
break;
default:
Console.WriteLine("Invalid selection. Please enter a valid number.");
break;
}
}
private void AddAnimal()
{
Console.WriteLine("Enter the animal's id");
if (int.TryParse(Console.ReadLine(), out int id))
{
Console.WriteLine("Enter the animal's species (Dog or Cat)");
if (Enum.TryParse(Console.ReadLine(), out Species species))
{
Console.WriteLine("Enter the animal's age");
if (int.TryParse(Console.ReadLine(), out int age))
{
Console.WriteLine("Enter the animal's characteristic description");
string characteristicDescription = Console.ReadLine();
Console.WriteLine("Enter the animal's personality description");
string personalityDescription = Console.ReadLine();
Console.WriteLine("Enter the animal's nickname");
string nickname = Console.ReadLine();
Animal newAnimal = new Animal(id, species, age, characteristicDescription, personalityDescription, nickname);
Data.AddAnimal(newAnimal);
Console.WriteLine("Animal added successfully!");
}
else
{
Console.WriteLine("Invalid age. Please enter a valid number.");
}
}
else
{
Console.WriteLine("Invalid species. Please enter Dog or Cat.");
}
}
else
{
Console.WriteLine("Invalid id. Please enter a valid number.");
}
}
private void EditAnimalAge()
{
Console.Write("Enter the animal's id: ");
if (int.TryParse(Console.ReadLine(), out int id))
{
Console.Write("Enter the animal's new age: ");
if (int.TryParse(Console.ReadLine(), out int newAge))
{
Data.EditAnimal(id, newAge);
Console.WriteLine("Animal age updated successfully!");
}
else
{
Console.WriteLine("Invalid age. Please enter a valid number.");
}
}
else
{
Console.WriteLine("Invalid id. Please enter a valid number.");
}
}
private void EditAnimalPersonalityDescription()
{
Console.Write("Enter the animal's id: ");
if (int.TryParse(Console.ReadLine(), out int id))
{
Console.Write("Enter the animal's new personality description: ");
string newPersonalityDescription = Console.ReadLine();
Data.EditAnimal(id, newPersonalityDescription);
Console.WriteLine("Animal personality description updated successfully!");
}
else
{
Console.WriteLine("Invalid id. Please enter a valid number.");
}
}
private void DisplayAnimalsWithSpecificCharacteristics(Species species)
{
Console.Write($"Enter the characteristic you are looking for in {species}s: ");
string characteristic = Console.ReadLine();
Data.DisplayAnimal(species, characteristic);
}
private void EnsureCharacteristicsComplete(params string[] characteristics)
{
Data.EnsureCompletion(characteristics);
}
public override string ToString()
{
return $"id: {Id}\nSpecies: {Species}\nAge: {Age}\nNickname: {Nickname}\nDescription: {CharacteristicDescription}\nPersonality: {PersonalityDescription}";
}
}
}