/
Animal.cs
60 lines (50 loc) · 1.16 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
using System;
using System.Collections.Generic;
class Pet
{
public string Name;
public string Species;
public int Age;
}
public class Program
{
public static void Main()
{
Pet fluffy = new Pet();
fluffy.Name = "Fluffy";
fluffy.Species = "Cat";
fluffy.Age = 5;
Pet spot = new Pet();
spot.Name = "Spot";
spot.Species = "Dog";
spot.Age = 5;
Pet ace = new Pet();
ace.Name = "Ace";
ace.Species = "Dog";
ace.Age = 8;
Pet tom = new Pet();
tom.Name = "Tom";
tom.Species = "Cat";
tom.Age = 5;
List<Pet> Pets = new List<Pet>() {fluffy, spot, ace, tom};
foreach(Pet animal in Pets)
{
Console.WriteLine(animal.Name);
}
Console.WriteLine("Enter the maximum age pet you are looking for.");
string stringMaxAge = Console.ReadLine();
int maxAge = int.Parse(stringMaxAge);
List <Pet> PetsMatchingSearch = new List<Pet>();
foreach(Pet animal in Pets)
{
if (animal.Age <= maxAge)
{
PetsMatchingSearch.Add(animal);
}
}
foreach(Pet animal in PetsMatchingSearch)
{
Console.WriteLine(animal.Name);
}
}
}