static void GiveTreat(IDog dog) { if (dog is GermanShepherd) { ((GermanShepherd)dog).SniffForDrugs(); } dog.Bark(); }
public static void Bark(IDog dog) { dog.Bark(); }
static void Main(string[] args) { Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); tryAgain: for (int i = 0; i < 50; i++) { if (rand.Next(0, 11) == 1) { if (rand.Next(0, 2) == 0) { int age = 0; bool valid = false; Console.WriteLine("you bought a Dog!"); Console.WriteLine("What do you want your dog to be named?"); string Dname = Console.ReadLine(); Console.WriteLine("How old is " + Dname + "?"); do { string temp = Console.ReadLine(); try { age = Convert.ToInt32(temp); valid = true; } catch { Console.WriteLine("Please enter a number."); } } while (valid == false); valid = false; Console.WriteLine("what is " + Dname + "'s license number?"); string Dlicesnse = Console.ReadLine(); //dog = (Dog)thisPet; thisPet = new Dog(Dname, Dlicesnse, age); } else { bool valid = false; Console.WriteLine("you bought a Cat!"); Console.WriteLine("What do you want your Cat to be named?"); string Cname = Console.ReadLine(); Console.WriteLine("How old is " + Cname + "?"); do { try { int age = Convert.ToInt32(Console.ReadLine()); valid = true; } catch { Console.WriteLine("Please enter a number."); } } while (valid == false); valid = false; Console.WriteLine("what is " + Cname + "'s license number?"); string Clicense = Console.ReadLine(); thisPet = new Cat(); } } else { thisPet = pets[rand.Next(0, pets.count)]; if (thisPet == null) { goto tryAgain; } } if (thisPet.GetType() == typeof(Cat)) { iCat = (ICat)thisPet; int rando = rand.Next(0, 4); switch (rando) { case 0: iCat.Eat(); break; case 1: iCat.Play(); break; case 2: iCat.Purr(); break; case 3: iCat.Scratch(); break; default: Console.WriteLine("this fell through for some reason"); break; } } else { //thisPet = (Pet)iDog; int rando = rand.Next(0, 5); iDog = (IDog)thisPet; switch (rando) { case 0: iDog.Eat(); break; case 1: iDog.Play(); break; case 2: iDog.Bark(); break; case 3: iDog.NeedWalk(); break; case 4: iDog.GotoVet(); break; default: Console.WriteLine("this fell through for some reason"); break; } } } }
public void FakeBark() { dog.Bark(); }
public void Execute(IJobExecutionContext context) { Console.WriteLine("------------------------{0}------------------------", context.FireTimeUtc.Value.ToLocalTime()); _dog.Bark(); _dog.ChaseMailman(8); }
public string SoundDog() => dog.Bark();
static void Main(string[] args) { int i = 0; int petEl = 0; Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; // seed the random number generator Random rand = new Random(); Pets pets = new Pets(); Timer myTimer = new Timer(20000); myTimer.Elapsed += (sender, e) => Dog.EvictCat(sender, e, pets); //myTimer.Elapsed += (sender, e) => Console.WriteLine("yes"); myTimer.Start(); for (i = 0; i < 50; ++i) { // 1 in 10 chance of adding an animal if (rand.Next(1, 11) == 1) { Console.WriteLine(); if (rand.Next(1, 3) == 1) { // add a cat cat = new Cat(); Console.WriteLine("You bought a cat!"); Console.Write("Cat's Name => "); cat.Name = Console.ReadLine(); Console.Write("Age => "); cat.age = Convert.ToInt32(Console.ReadLine()); thisPet = cat; } else { // add a dog string szLicense; string szName; int nAge; Console.WriteLine("You bought a dog!"); Console.Write("Dog's Name => "); szName = Console.ReadLine(); Console.Write("Age => "); nAge = Convert.ToInt32(Console.ReadLine()); Console.Write("License => "); szLicense = Console.ReadLine(); dog = new Dog(szLicense, szName, nAge); thisPet = dog; } pets.Add(thisPet); } else { petEl = rand.Next(0, pets.Count); thisPet = pets[petEl]; if (thisPet == null) { continue; } if (thisPet.GetType() == typeof(Cat)) { iCat = (ICat)thisPet; int nAction = rand.Next(0, 4); switch (nAction) { case 0: iCat.Eat(); break; case 1: iCat.Play(); break; case 2: iCat.Purr(); break; case 3: iCat.Scratch(); break; } } else { iDog = (IDog)thisPet; int nAction = rand.Next(0, 5); switch (nAction) { case 0: iDog.Eat(); break; case 1: iDog.Play(); break; case 2: iDog.Bark(); break; case 3: iDog.NeedWalk(); break; case 4: iDog.GotoVet(); break; } } } } }
static void Main(string[] args) { // Create reference variables for pets and interfaces Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); for (int i = 0; i < 50; i++) { start: // 1 in 10 chance of adding an animal if (rand.Next(1, 11) == 1) { // 50% chance of adding a dog if (rand.Next(0, 2) == 0) { // Upon winning the dog, initialize variables and ask for each of their values Console.WriteLine("Congratulations, you won a dog!"); string license = null; string name = null; int age = 0; Console.Write("What is its age? "); do { try { age = Int16.Parse(Console.ReadLine()); } catch { Console.Write("Please enter an integer: "); } } while (age <= 0); Console.WriteLine("What will you call it? "); try { name = Console.ReadLine(); } catch { } Console.WriteLine("Give it a license #: "); try { license = Console.ReadLine(); } catch { } // Create new dog passing values to its constructor, and add it to petList pets.Add(dog = new Dog(license, name, age)); Console.WriteLine("License: #" + license + ", Name: " + name + ", Age: " + age); } else { // else add a cat // Upon winning the dog, initialize variables and ask for each of their values Console.WriteLine("Congratulations, you won a cat!"); string name = null; int age = 0; Console.Write("What is its age? "); do { try { age = Int16.Parse(Console.ReadLine()); } catch { Console.Write("\r"); Console.Write("Please enter an integer: "); } } while (age <= 0); Console.WriteLine("What will you call it? "); try { name = Console.ReadLine(); } catch { } // Create new cat passing values to its constructor, and add it to petList pets.Add(cat = new Cat(name, age)); Console.WriteLine("Name: " + name + ", Age: " + age); } } else { try { // Get a random pet from petList and make it do something if (thisPet.GetType() == typeof(Cat)) { iCat = (ICat)thisPet; // make the cat do something random int nAction = rand.Next(0, 4); switch (nAction) { case 0: iCat.Eat(); break; case 1: iCat.Scratch(); break; case 2: iCat.Play(); break; case 3: iCat.Purr(); break; case 4: iDog.GotoVet(); break; } } // Get a random pet from petList and make it do something else if (thisPet.GetType() == typeof(Dog)) { iDog = (IDog)thisPet; // make the cat do something random int nAction = rand.Next(0, 4); switch (nAction) { case 0: iDog.Eat(); break; case 1: iDog.NeedWalk(); break; case 2: iCat.Play(); break; case 3: iDog.Bark(); break; case 4: iDog.GotoVet(); break; } } } catch { goto start; } } Console.WriteLine(i); } }
//Method: Main //Purpose: Create instances of pets static void Main(string[] args) { string name; int age; string license; Pet thisPet = null; Dog dog = null; Cat cat = null; IDog iDog = null; ICat iCat = null; Pets pets = new Pets(); Random rand = new Random(); for (int i = 0; i < 50; i++) { if (rand.Next(1, 11) == 1) { if (rand.Next(0, 2) == 0) { Console.WriteLine("You bought a dog!"); Console.Write("Dog's Name => "); name = Console.ReadLine(); Console.Write("Age => "); while (true) { try { age = int.Parse(Console.ReadLine()); break; } catch { Console.Write("Age => "); } } Console.Write("License => "); license = Console.ReadLine(); thisPet = new Dog(license, name, age); } else { Console.WriteLine("You bought a cat!"); Console.Write("Cat's Name => "); name = Console.ReadLine(); Console.Write("Age => "); while (true) { try { age = int.Parse(Console.ReadLine()); break; } catch { Console.Write("Age => "); } } cat = new Cat(); thisPet = cat; thisPet.Name = name; thisPet.age = age; } } else { thisPet = pets[rand.Next(0, pets.Count)]; } if (thisPet != null) { if (thisPet.GetType() == typeof(Cat)) { iCat = (ICat)thisPet; int choice = rand.Next(0, 4); if (choice == 0) { iCat.Eat(); } else if (choice == 1) { iCat.Play(); } else if (choice == 2) { iCat.Scratch(); } else { iCat.Purr(); } } else { iDog = (IDog)thisPet; int choice = rand.Next(0, 5); if (choice == 0) { iDog.Eat(); } else if (choice == 1) { iDog.Play(); } else if (choice == 2) { iDog.Bark(); } else if (choice == 3) { iDog.NeedWalk(); } else { iDog.GotoVet(); } } } } }
public async Task <ActionResult <DogInfo> > Bark(BarkRequest req) { return(await _dog.Bark(req)); }