示例#1
0
        public static void GetAnimalsFromShelter()
        {
            AnimalShelter myShelter = MakeAnimalShelter();

            Console.WriteLine($"Animal shelter made and last animal added is {myShelter.InBoundStack.Peek().Name}");
            Console.WriteLine($"first cat returned should be mike it is: {myShelter.Dequeue("cat").Name}");
            Console.WriteLine($"first dog returned should be spot it is: {myShelter.Dequeue("dog").Name}");
            Console.WriteLine($"second dog returned should be demi it is: {myShelter.Dequeue("dog").Name}");
            Console.WriteLine($"second cat returned should be ron it is: {myShelter.Dequeue("cat").Name}");
        }
        static void Main(string[] args)
        {
            Animal cat1 = new Cat("cat1");
            Animal cat2 = new Cat("cat2");
            Animal cat3 = new Cat("cat3");
            Animal dog1 = new Dog("dog1");
            Animal dog2 = new Dog("dog2");
            Animal dog3 = new Dog("dog3");
            Animal fish = new Fish("fish");

            AnimalShelter shelter = new AnimalShelter(cat1);

            shelter.Enqueue(cat2);
            shelter.Enqueue(cat3);
            shelter.Enqueue(dog1);
            shelter.Enqueue(dog2);
            shelter.Enqueue(dog3);
            shelter.Enqueue(fish);

            Console.WriteLine(shelter.Dequeue("dog").Name);

            Console.WriteLine(shelter.Front.Name);
        }
示例#3
0
        static void Main(string[] args)
        {
            Cat cat1 = new Cat("cat 1");
            Cat cat2 = new Cat("cat 2");
            Cat cat3 = new Cat("cat 3");
            Cat cat4 = new Cat("cat 4");
            Dog dog1 = new Dog("dog 1");
            Dog dog2 = new Dog("dog 2");
            Dog dog3 = new Dog("dog 3");


            AnimalShelter shelter = new AnimalShelter(dog1);

            shelter.Enqueue(cat1);
            shelter.Enqueue(dog2);
            shelter.Enqueue(dog3);
            shelter.Enqueue(cat2);
            shelter.Enqueue(cat3);
            shelter.Enqueue(cat4);

            Console.WriteLine($"First animal in queue is: {shelter.Peek().Value}");
            Console.WriteLine($"Check for first cat in queue: {shelter.Dequeue("cat").Value}");
            Console.WriteLine($"Check firt animal in queue even after previous dequeue: {shelter.Peek().Value}");
        }
示例#4
0
        /// <summary>
        ///     Instantiates and runs an AnimalShelter instance for CLI
        /// </summary>
        static void FifoAnimalShelter()
        {
            AnimalShelter shelter = new AnimalShelter();

            List <Animal> animals = new List <Animal>();

            Cat wiskers = new Cat();
            Cat bonkers = new Cat();
            Cat catters = new Cat();
            Dog spot    = new Dog();
            Dog bone    = new Dog();
            Dog wags    = new Dog();

            animals.Add(wiskers);
            animals.Add(spot);
            animals.Add(bonkers);
            animals.Add(catters);
            animals.Add(bone);
            animals.Add(wags);

            foreach (var animal in animals)
            {
                shelter.Enqueue(animal);
            }


            while (true)
            {
                Console.WriteLine("Welcome to Rainin' Cats and Dogs!");
                Console.WriteLine("1] Adopt");
                Console.WriteLine("2] Deopt");
                string selectAction = Console.ReadLine();


                if (selectAction == "1")
                {
                    Console.WriteLine("Adopt: Cat or Dog?");
                    Console.WriteLine("1] Cat");
                    Console.WriteLine("2] Dog");
                    string selectType = Console.ReadLine();

                    if (selectType == "1")
                    {
                        Cat adopteeCat = (Cat)shelter.Dequeue("cat");
                        Console.WriteLine("Cat with tag: " + adopteeCat.ID + " says " + adopteeCat.MakeNoise() + "[Thanks for atopting me!]");
                        Console.ReadLine();
                        Console.Clear();
                    }

                    if (selectType == "2")
                    {
                        Dog adopteeDog = (Dog)shelter.Dequeue("dog");
                        Console.WriteLine("Dog with tag: " + adopteeDog.ID + " says " + adopteeDog.MakeNoise() + "[Thanks for atopting me!]");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    else
                    {
                        Console.WriteLine("I'm sorry, what?");
                        Console.ReadLine();
                        Console.Clear();
                    }
                }
                else if (selectAction == "2")
                {
                    Console.WriteLine("Adopt: Cat or Dog?");
                    Console.WriteLine("1] Cat");
                    Console.WriteLine("2] Dog");
                    string selectType = Console.ReadLine();


                    if (selectType == "1")
                    {
                        Cat deCat = new Cat();
                        Console.WriteLine(deCat.MakeNoise() + " [bye!]");
                        shelter.Enqueue(deCat);
                        Console.ReadLine();
                        Console.Clear();
                    }
                    else if (selectType == "2")
                    {
                        Dog deDog = new Dog();
                        Console.WriteLine(deDog.MakeNoise() + " [bye!]");
                        shelter.Enqueue(deDog);
                        Console.ReadLine();
                        Console.Clear();
                    }
                    else
                    {
                        Console.WriteLine("Um.. cat or dog?");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("Please select 1 or 2");
                }
            }
        }