using System.Collections.Generic;
public static void Main()
f.Animals.Add(new FarmAnimal("A-1234", new DateTime(2017, 2, 7), "M", 10, "Brown Spotted"));
f.Animals.Add(new FarmAnimal("A-2345", new DateTime(2017, 3, 20), "F", 15, "Red"));
f.Animals.Add(new Chicken(Chicken.ChickenBreed.Brahma, 1000, "CK-3456", new DateTime(2017, 4, 1), "F", 1, "Gray Speckled"));
f.Animals.Add(new Chicken(Chicken.ChickenBreed.Cochin, 1001, "CK-4567", new DateTime(2017, 4, 1), "M", 2, "Red"));
f.Animals.Add(new Chicken(Chicken.ChickenBreed.Leghorn, 1002, "CK-5678", new DateTime(2017, 4, 3), "F", 1, "Black"));
f.Animals.Add(new Cow(Cow.CowBreed.Holstein, 3, "CW-6789", new DateTime(2017, 1, 7), "M", 2034, "White with Black Spots"));
f.Animals.Add(new Cow(Cow.CowBreed.Jersey, 7, "CW-7890", new DateTime(2017, 2, 4), "F", 1578, "Tan"));
Console.WriteLine("Checking the Types of Animals using GetType");
Console.WriteLine("***********************");
foreach(FarmAnimal a in f.Animals)
if (a.GetType() == typeof(FarmAnimal))
Console.WriteLine(String.Format("Animal {0} is specifically of the type FarmAnimal.", a.TagNum));
Console.WriteLine(String.Format("Animal {0} is NOT specifically of the type FarmAnimal.", a.TagNum));
Console.WriteLine("Checking the Types of Animals using the Is operator");
Console.WriteLine("***********************");
foreach(FarmAnimal a in f.Animals)
Console.WriteLine(String.Format("Animal {0} is a FarmAnimal.", a.TagNum));
Console.WriteLine(String.Format("Animal {0} is NOT a FarmAnimal.", a.TagNum));
f.FeedTheAnimals(FarmAnimal.Food.Corn);
f.FeedTheAnimals(FarmAnimal.Food.Hay);
public List<FarmAnimal> Animals { get; set; }
Animals = new List<FarmAnimal>();
public void FeedTheAnimals(FarmAnimal.Food food)
Console.WriteLine("Feeding the Animals");
Console.WriteLine("*******************");
foreach (FarmAnimal a in Animals)
public void CheckTheAnimals()
Console.WriteLine("Checking the Animals");
Console.WriteLine("***********************");
foreach (FarmAnimal a in Animals)
Checkup check = new Checkup(i, DateTime.Now, "Matt", "This animal looks healthy and happpy.");
public void PrintTheAnimals()
Console.WriteLine("Printing the Animals");
Console.WriteLine("*******************");
foreach (FarmAnimal a in Animals)
Console.Write(a.ToString());
public void ListenToTheAnimals()
Console.WriteLine("Listening to the Animals");
Console.WriteLine("***********************");
foreach (FarmAnimal a in Animals)
public void CollectTheEggs()
Console.WriteLine("Collecting the Eggs");
Console.WriteLine("*******************");
foreach (FarmAnimal a in Animals)
public void MilkTheCows()
Console.WriteLine("Milk the Cows");
Console.WriteLine("*************");
foreach (FarmAnimal a in Animals)
if (a.GetType() == typeof(Cow))
public class FarmAnimal : Object
public enum Food { Corn, Seed, Hay, Grass }
public string TagNum { get; set; }
public DateTime DateOfBirth { get; set; }
public string Sex { get; set; }
public short Weight { get; set; }
public string ColorMarkings { get; set; }
public List<Checkup> Checkups { get; set; }
public FarmAnimal(string tagNum, DateTime dateOfBirth, string sex, short weight, string colorMarkings)
DateOfBirth = dateOfBirth;
ColorMarkings = colorMarkings;
Checkups = new List<Checkup>();
public virtual void Eat(Food food)
Console.WriteLine("Yummy, all animals like corn.");
Console.WriteLine("Hmmm, I am not sure I like this.");
public void LogCheckup(Checkup checkup)
Console.WriteLine(String.Format("{0}, thank you for the checkup.", checkup.CheckedBy));
public virtual void Speak()
Console.WriteLine("generic animal sounds");
public override string ToString()
strOutput += "Generic Farm Animal" + Environment.NewLine;
strOutput += "-------------------" + Environment.NewLine;
strOutput += "Tag Number: " + TagNum + Environment.NewLine;
strOutput += "Date of Birth: " + DateOfBirth.ToShortDateString() + Environment.NewLine;
strOutput += "Sex: " + Sex + Environment.NewLine;
strOutput += "Weight: " + Weight + Environment.NewLine;
strOutput += "Color/Markings: " + ColorMarkings + Environment.NewLine;
strOutput += "Number of Checkups: " + Checkups.Count.ToString() + Environment.NewLine;
public int ID { get; set; }
public DateTime CheckupDate { get; set; }
public string CheckedBy { get; set; }
public string Notes { get; set; }
public Checkup(int id, DateTime checkupDate, string checkedBy, string notes)
CheckupDate = checkupDate;
public class Chicken : FarmAnimal
public enum ChickenBreed { Araucana, Brahma, Cochin, Leghorn, NewHampshireRed, OldEnglishGame, Orpington, RhodeIslandRed, RhodeIslandWhite }
public ChickenBreed Breed { get; set; }
public int HouseNum { get; set; }
public Chicken(ChickenBreed breed, int houseNum, string tagNum, DateTime dateOfBirth, string sex, short weight, string colorMarkings)
base.DateOfBirth = dateOfBirth;
base.ColorMarkings = colorMarkings;
base.Checkups = new List<Checkup>();
public override void Eat(Food food)
Console.WriteLine("Yummy, chickens like this.");
Console.WriteLine("Yuck, chickens don't like this.");
public override void Speak()
Console.WriteLine("cluck cluck cluck");
public override string ToString()
string strOutput = base.ToString();
strOutput = strOutput.Replace("Generic Farm Animal", "Chicken");
strOutput += "Breed: " + Breed.ToString() + Environment.NewLine;
strOutput += "House Number: " + HouseNum.ToString() + Environment.NewLine;
Console.WriteLine("layed 1 egg");
Console.WriteLine("sorry, roosters don't lay eggs");
public class Cow : FarmAnimal
public enum CowBreed { Holstein, Jersey, Guernsey, Ayrshire, BrownSwiss }
public CowBreed Breed { get; set; }
public int FieldNum { get; set; }
public Cow(CowBreed breed, int fieldNum, string tagNum, DateTime dateOfBirth, string sex, short weight, string colorMarkings) :
base(tagNum, dateOfBirth, sex, weight, colorMarkings)
public override void Eat(Food food)
Console.WriteLine("Yummy, cows like this.");
Console.WriteLine("Yuck, cows don't like this.");
public override void Speak()
Console.WriteLine("mooooo mooooo");
public override string ToString()
string strOutput = base.ToString();
strOutput = strOutput.Replace("Generic Farm Animal", "Cow");
strOutput += "Breed: " + Breed.ToString() + Environment.NewLine;
strOutput += "Field Number: " + FieldNum.ToString() + Environment.NewLine;
public void ProduceMilk()
Console.WriteLine("produced 1 gallon of milk");
Console.WriteLine("sorry, bulls don't produce milk");