public void SheepSearch() { Console.Clear(); Console.Write("Enter the name of the Sheep you wish to get info on: "); string hSearch = Console.ReadLine(); Sheep match = SheepList.Find((Sheep hor) => { return(hor.name == hSearch); }); Console.WriteLine("name: {0}, age: {1}, fun: {2}, food: {3}", match.name, match.age, match.fun, match.food); Console.ReadLine(); Console.Clear(); return; }
public void SheepFriend() { Console.WriteLine("Tell me about your sheep\n" + "What kind of food does he eat?"); string food = Console.ReadLine(); Console.WriteLine("How old is it in years?"); int age = int.Parse(Console.ReadLine()); Console.WriteLine("What does your sheep do for fun?"); string fun = Console.ReadLine(); Console.WriteLine("Finally whats your sheep's name???"); string name = Console.ReadLine(); Sheep sampleSheep = new Sheep(food, age, fun, name); SheepList.Add(sampleSheep); Console.Clear(); Console.WriteLine("The information for your Sheep has been saved.\n" + "What else would you like to do?\n"); return; }
public void SheepProg(string food, int age, string fun, string name) { Sheep sampleAnimal = new Sheep(food, age, fun, name); SheepList.Add(sampleAnimal); Console.Clear(); Console.WriteLine("The information for your sheep has been saved.\n" + "What else would you like to do?"); HMAIN: Console.WriteLine("1) Exit\n" + "2) List all my sheep\n" + "3) Search for a specific sheep\n" + "4) Feed the sheep\n" + "5) Play with the sheep\n" + "6) Add another sheep friend"); int animalChoice = int.Parse(Console.ReadLine()); switch (animalChoice) { case 1: { return; } case 2: { SavedSheep(); goto HMAIN; } case 3: { SheepSearch(); goto HMAIN; } case 4: { FeedSheep(); goto HMAIN; } case 5: { SheepPlay(); goto HMAIN; } case 6: { SheepFriend(); goto HMAIN; } default: { Console.Clear(); Console.WriteLine("Thats not an available choice, please pick a number 1-6"); goto HMAIN; } } }
static void Main(string[] args) { // try catch block that catches only format exceptions and general exceptions try { MainMenu(); } catch (FormatException fEx) { Console.WriteLine(fEx.Message); Console.ReadKey(); } catch (Exception gEx) { Console.WriteLine(gEx.Message); Console.ReadKey(); } void MainMenu() { Console.WriteLine("Please enter a number value for the farm animal you want to play with:\n\n" + "1) Exit Program\n" + "2) Horse\n" + "3) Cow\n" + "4) Cat\n" + "5) Sheep\n"); int choice = int.Parse(Console.ReadLine()); switch (choice) { // immediately exits case 1: { return; } case 2: { // user inputs for the arguments for the instance of class horse Console.Clear(); Console.WriteLine("Tell me about your horse\n" + "What kind of food does he eat?"); string Hfood = Console.ReadLine(); Console.WriteLine("How old is it in years?"); int Hage = int.Parse(Console.ReadLine()); Console.WriteLine("What does your horse do for fun?"); string Hfun = Console.ReadLine(); Console.WriteLine("Finally whats your horse's name???"); string Hname = Console.ReadLine(); // instance initialized Horse sampleHorse = new Horse(Hfood, Hage, Hfun, Hname); // sampleHorse calls the program with arguments Hfood,Hage,Hfun,Hname sampleHorse.HorseProg(Hfood, Hage, Hfun, Hname); break; } case 3: { Console.Clear(); Console.WriteLine("Tell me about your cow\n" + "What kind of food does he eat?"); string food = Console.ReadLine(); Console.WriteLine("How old is it in years?"); int age = int.Parse(Console.ReadLine()); Console.WriteLine("What does your cow do for fun?"); string fun = Console.ReadLine(); Console.WriteLine("Finally whats your cow's name???"); string name = Console.ReadLine(); Cow sampleAnimal = new Cow(food, age, fun, name); sampleAnimal.CowProg(food, age, fun, name); break; } case 4: { Console.Clear(); Console.WriteLine("Tell me about your cat\n" + "What kind of food does he eat?"); string food = Console.ReadLine(); Console.WriteLine("How old is it in years?"); int age = int.Parse(Console.ReadLine()); Console.WriteLine("What does your cat do for fun?"); string fun = Console.ReadLine(); Console.WriteLine("Finally whats your cat's name???"); string name = Console.ReadLine(); Cat sampleAnimal = new Cat(food, age, fun, name); sampleAnimal.CatProg(food, age, fun, name); break; } case 5: { Console.Clear(); Console.WriteLine("Tell me about your sheep\n" + "What kind of food does he eat?"); string food = Console.ReadLine(); Console.WriteLine("How old is it in years?"); int age = int.Parse(Console.ReadLine()); Console.WriteLine("What does your sheep do for fun?"); string fun = Console.ReadLine(); Console.WriteLine("Finally whats your sheep's name???"); string name = Console.ReadLine(); Sheep sampleAnimal = new Sheep(food, age, fun, name); sampleAnimal.SheepProg(food, age, fun, name); break; } // default will catch all inputs that are not between 1 - 5 default: { Console.Clear(); Console.WriteLine("Please enter a value 1-5 ONLY!\n" + "press enter to acknowledge"); Console.ReadLine(); Console.Clear(); MainMenu(); break; } } } }