Exemple #1
0
        public static void AnimalShelterFIFO()
        {
            Animal cat1 = new Cat();
            Animal dog1 = new Dog();
            Animal cat2 = new Cat();
            Animal dog2 = new Dog();
            Animal dog3 = new Dog();

            AnimalShelter AShelter = new AnimalShelter(cat1);

            AShelter.Enqueue(dog1);
            AShelter.Enqueue(cat2);
            AShelter.Enqueue(dog2);
            AShelter.Enqueue(dog3);

            Console.WriteLine(cat1.Name);
            Console.WriteLine(dog1.Name);
            Console.WriteLine(cat2.Name);
            Console.WriteLine(dog2.Name);
            Console.WriteLine(dog3.Name);


            Console.WriteLine("Dequeue front animal: cat");
            Console.WriteLine(AShelter.Dequeue("cat").Name);

            Console.WriteLine("Dequeue not front cat.");
            Console.WriteLine(AShelter.Dequeue("cat").Name);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Dog           dog     = new Dog();
            AnimalShelter shelter = new AnimalShelter();

            shelter.Enqueue(dog);
            Animal animal = shelter.Dequeue("cat");
        }
        static void Main(string[] args)
        {
            AnimalShelter shelter = new AnimalShelter();

            FIFOAnimalShelter(shelter);

            Console.ReadLine();
        }
Exemple #4
0
        /// <summary>
        /// This tests if the dequeueing works
        /// </summary>
        static void DequeueTheShelter()
        {
            AnimalShelter shelter = new AnimalShelter();

            Dog dog = new Dog()
            {
                Name = "Spot", Loudness = 10m
            };

            shelter.Enqueue(dog);

            Cat cat = new Cat()
            {
                Name = "Josie", Cuteness = 200m
            };

            shelter.Enqueue(cat);

            Dog dog1 = new Dog()
            {
                Name = "Leo", Loudness = 3m
            };

            shelter.Enqueue(dog);

            Cat cat1 = new Cat()
            {
                Name = "Razzle", Cuteness = 4000m
            };

            shelter.Enqueue(cat);

            Dog dog2 = new Dog()
            {
                Name = "Spike", Loudness = 55m
            };

            shelter.Enqueue(dog);

            Cat cat2 = new Cat()
            {
                Name = "Crazy", Cuteness = 6000m
            };

            shelter.Enqueue(cat);

            Cat emptyCat = new Cat();
            Dog emptyDog = new Dog();

            Animal animal = shelter.Dequeue("dog");

            Console.WriteLine(animal.Name);
        }
        /// <summary>
        /// demonstrates Enqueue and Dequeue behaviors for standard and edge cases
        /// </summary>
        /// <param name="shelter"> AnimalShelter object (empty) to test behaviors </param>
        static void FIFOAnimalShelter(AnimalShelter shelter)
        {
            Console.WriteLine("*** EMPTY SHELTER ***");
            Console.WriteLine("Retrieve dog from empty shelter:");
            shelter.Dequeue("dog");

            Console.WriteLine("Retrieve cat from empty shelter:");
            shelter.Dequeue("cat");

            Console.WriteLine("\n*** ADD SOME CRITTERS TO THE SHELTER ***");
            Dog rocket = new Dog("Rocket");
            Cat bart   = new Cat("Bart");
            Dog bandit = new Dog("Bandit");
            Cat bongo  = new Cat("Bongo");
            Dog zuni   = new Dog("Zuni");

            shelter.Enqueue(rocket);
            Console.WriteLine($"Added {shelter.Primary.Rear.Name} the {shelter.Primary.Rear.Species} to the shelter.");
            shelter.Enqueue(bart);
            Console.WriteLine($"Added {shelter.Primary.Rear.Name} the {shelter.Primary.Rear.Species} to the shelter.");
            shelter.Enqueue(bandit);
            Console.WriteLine($"Added {shelter.Primary.Rear.Name} the {shelter.Primary.Rear.Species} to the shelter.");
            shelter.Enqueue(bongo);
            Console.WriteLine($"Added {shelter.Primary.Rear.Name} the {shelter.Primary.Rear.Species} to the shelter.");
            shelter.Enqueue(zuni);
            Console.WriteLine($"Added {shelter.Primary.Rear.Name} the {shelter.Primary.Rear.Species} to the shelter.");

            Console.WriteLine("\n*** HOST AN ADOPT-A-PET DAY IN THE WENDY'S PARKING LOT ***");

            Animal adopted = shelter.Dequeue("dog");

            Console.WriteLine($"{adopted.Name} the {adopted.Species} has been adopted! {shelter.Primary.Front.Name} the {shelter.Primary.Front.Species} is first in line.");
            adopted = shelter.Dequeue("dog");
            Console.WriteLine($"{adopted.Name} the {adopted.Species} has been adopted! {shelter.Primary.Front.Name} is first in line.");
            adopted = shelter.Dequeue("cat");
            Console.WriteLine($"{adopted.Name} the {adopted.Species} has been adopted! {shelter.Primary.Front.Name} the {shelter.Primary.Front.Species} is first in line.");

            Console.WriteLine("\n*** SOMEONE WANTS A PET-GRAB-BAG ***");
            adopted = shelter.Dequeue("");
            Console.WriteLine($"{adopted.Name} the {adopted.Species} has been adopted! {shelter.Primary.Front.Name} is first in line.");

            Console.WriteLine("\n*** A TEENAGER WANTS A BABBOON ***");
            adopted = shelter.Dequeue("babboon");
        }
Exemple #6
0
        static void Main(string[] args)
        {
            AnimalShelter shelter = new AnimalShelter(new Dog("Moby"));

            shelter.Enqueue(new Cat("Boots"));
            shelter.Enqueue(new Dog("Coco"));
            Console.WriteLine(shelter.Dequeue("cat").Name);
            Console.WriteLine(shelter.Dequeue("dog").Name);
            Console.WriteLine(shelter.Dequeue("").Name);
            try
            {
                Console.WriteLine(shelter.Dequeue("dog"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
        static void FIFOAnimalShelter()
        {
            AnimalShelter shelter = new AnimalShelter();

            shelter.Enqueue(new Animal("Dog"));
            shelter.Enqueue(new Animal("Dog"));
            shelter.Enqueue(new Animal("Dog"));
            shelter.Enqueue(new Animal("Dog"));
            shelter.Enqueue(new Animal("Cat"));
            shelter.Enqueue(new Animal("Cat"));
            Console.WriteLine(shelter.Dequeue("cat").Value);
            Console.WriteLine(shelter.Dequeue("cat").Value);
            Console.WriteLine(shelter.Dequeue("cat").Value);
            Console.WriteLine(shelter.Dequeue("dog").Value);
            Console.WriteLine(shelter.Dequeue("dog").Value);
            Console.WriteLine(shelter.Dequeue("dog").Value);
            Console.WriteLine(shelter.Dequeue("dog").Value);
            Console.WriteLine(shelter.Dequeue("dog").Value);
        }
Exemple #8
0
        static void FIFOAnimalShelter()
        {
            Cat cat1 = new Cat();
            Cat cat2 = new Cat();
            Dog dog1 = new Dog();
            Dog dog2 = new Dog();

            AnimalShelter animalShelter = new AnimalShelter(cat1);

            animalShelter.Enqueue(dog1);
            animalShelter.Enqueue(dog2);
            animalShelter.Enqueue(cat2);

            Console.WriteLine(animalShelter.Print());

            Console.WriteLine($"The animal taken out is {animalShelter.Dequeue("Dog").Name}");

            Console.WriteLine(animalShelter.Print());
        }
Exemple #9
0
        public static void FIFOAnimalShelter()
        {
            Animal dog1 = new Animal("dog");
            Animal dog2 = new Animal("dog");
            Animal dog3 = new Animal("dog");
            Animal cat1 = new Animal("cat");
            Animal cat2 = new Animal("cat");
            Animal cat3 = new Animal("cat");

            AnimalShelter Shelter = new AnimalShelter(dog1);

            Shelter.Enqueue(dog2);
            Shelter.Enqueue(dog3);
            Shelter.Enqueue(cat1);
            Shelter.Enqueue(cat2);
            Shelter.Enqueue(cat3);

            Console.WriteLine(dog1.AnimalType);
            Console.WriteLine(dog2.AnimalType);
            Console.WriteLine(dog3.AnimalType);
            Console.WriteLine(cat1.AnimalType);
            Console.WriteLine(cat2.AnimalType);
            Console.WriteLine(cat3.AnimalType);

            Console.WriteLine("dog" == "cat");

            Console.WriteLine("Dequeue animal at front: dog");

            Console.WriteLine(Shelter.Dequeue("dog").AnimalType);

            Console.WriteLine("===========================");

            Console.WriteLine("Dequeue animal not at front: cat");

            Console.WriteLine(Shelter.Dequeue("cat").AnimalType);

            Console.WriteLine("===========================");

            Console.WriteLine("Dequeue animal with bad target: zhevra");

            Console.WriteLine(Shelter.Dequeue("zhevra").AnimalType);
        }
Exemple #10
0
        /// <summary>
        /// This is a basic test to make sure that everything works
        /// </summary>
        static void FIFOAnimalShelter()
        {
            AnimalShelter animalShelter = new AnimalShelter(new Animal("cat"));

            animalShelter.Enqueue(new Animal("dog"));
            animalShelter.Enqueue(new Animal("cat"));
            animalShelter.Enqueue(new Animal("dog"));
            animalShelter.Enqueue(new Animal("dog"));
            animalShelter.Enqueue(new Animal("cat"));
            animalShelter.Enqueue(new Animal("dog"));
            animalShelter.Enqueue(new Animal("dog"));
            animalShelter.Enqueue(new Animal("dog"));
            animalShelter.Enqueue(new Animal("cat"));
            animalShelter.Enqueue(new Animal("cat"));
            animalShelter.Print();
            string pref           = "dog";
            Animal dequeuedAnimal = animalShelter.Dequeue(pref);

            animalShelter.Print();
            Console.WriteLine(dequeuedAnimal.Value);
        }
        static void Main(string[] args)
        {
            Dog dog1 = new Dog("dog 1!");
            Dog dog2 = new Dog("dog 2!");
            Dog dog3 = new Dog("dog 3!");
            Cat cat1 = new Cat("cat 1!");
            Cat cat2 = new Cat("cat 2!");

            AnimalShelter shelter = new AnimalShelter(dog1);

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

            Console.WriteLine($"First animal in queue is: {shelter.Peek().Value}");
            Console.WriteLine($"Grabbing first cat in queue: {shelter.Dequeue("cat").Value}");
            Console.WriteLine($"Checking that order is back to normal, first animal in queue now is still: {shelter.Peek().Value}");
            Console.WriteLine($"Grabbing first dog in queue: {shelter.Dequeue("dog").Value}");
            Console.WriteLine($"Now first animal in queue is: {shelter.Peek().Value}");
            Console.WriteLine($"Typing anything other than 'dog' or 'cat' will give us first animal: {shelter.Dequeue("horse").Value}");
        }
        public static void FIFOAnimalShelter()
        {
            Cat cat1 = new Cat("Fluffy");
            Cat cat2 = new Cat("Kitty");
            Dog dog1 = new Dog("Taco");
            Dog dog2 = new Dog("Zuzu");
            Dog dog3 = new Dog("Pepe");

            AnimalShelter animalShelter = new AnimalShelter(cat1);

            animalShelter.Enqueue(cat2);
            animalShelter.Enqueue(dog1);
            animalShelter.Enqueue(dog2);
            animalShelter.Enqueue(dog3);
            Animal someAnimal = animalShelter.DequeueWithType(typeof(Dog));

            Console.WriteLine($"The first available {someAnimal.GetType().Name} is called {someAnimal.Name}");
            someAnimal = animalShelter.DequeueWithType(typeof(Cat));
            Console.WriteLine($"The first available {someAnimal.GetType().Name} is called {someAnimal.Name}");
            someAnimal = animalShelter.DequeueWithType(typeof(Snake));
            Console.WriteLine($"The first available Snake is {(someAnimal != null ? someAnimal.Name : "N/A")}");
            someAnimal = animalShelter.DequeueWithType();
            Console.WriteLine($"The first available animal is a {someAnimal.GetType().Name} with a name {someAnimal.Name}");
        }
        /// <summary>
        /// Testing out Animal Shelter Method
        /// </summary>
        static void FIFOAnimalShelter()
        {
            Animal DogSpotty  = new Animal("Spotty", "Dog");
            Animal CatMittens = new Animal("Mittens", "Cat");
            Animal DogWoofy   = new Animal("Woofy", "Dog");
            Animal DogSpike   = new Animal("Spike", "Dog");
            Animal DogMrBeans = new Animal("MrBeans", "Dog");
            Animal CatFluffy  = new Animal("Fluffy", "Cat");
            Animal CatMrEvil  = new Animal("MrEvil", "Cat");
            Animal CatMisty   = new Animal("Misty", "Cat");

            List <Animal> AllMyAnimals = new List <Animal>()
            {
                DogSpotty, CatMittens, DogWoofy, DogSpike, DogMrBeans, CatFluffy, CatMrEvil, CatMisty
            };

            AnimalShelter MyAnimalShelter = new AnimalShelter();

            Console.WriteLine("The Shelter has the following animals in the order it was received:");
            foreach (var items in AllMyAnimals)
            {
                MyAnimalShelter.Enqueue(new Node(items));
                Console.WriteLine($"{items.Name} who is a {items.Type}");
            }

            Animal MyAnimal = (Animal)MyAnimalShelter.Peek().Data;

            Console.WriteLine($"{MyAnimal.Name} is at the Front of the Shelter");

            Animal ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Whatever").Data;

            MyAnimal = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"Any animal is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");

            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Dog").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Dog is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");

            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Cat").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Cat is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");


            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Cat").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Cat is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");


            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Cat").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Cat is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");


            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Dog").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Dog is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");


            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Lion").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Lion is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");

            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Dog").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Dog is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");

            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("W").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"Any animal is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");

            ReturnAnimal = (Animal)MyAnimalShelter.Dequeue("Dog").Data;
            MyAnimal     = (Animal)MyAnimalShelter.Peek().Data;
            Console.WriteLine($"A Dog is removed so {ReturnAnimal.Name} has been released and {MyAnimal.Name} is now at the front");

            Animal NewCat = new Animal("Bubbles", "Cat");
            Animal NewDog = new Animal("Labby", "Dog");

            MyAnimalShelter.Enqueue(new Node(NewCat));
            MyAnimalShelter.Enqueue(new Node(NewCat));
            MyAnimal = (Animal)MyAnimalShelter.Peek().Data;

            Console.WriteLine($"{NewCat.Name} who is a {NewCat.Type} has been added and {NewDog.Name} who is a {NewDog.Type} has been added so {MyAnimal.Name} is at the front.");
        }