Example #1
0
        public string RegisterAnimal(string type, string name, int energy, int happiness, int procedureTime)
        {
            Animal animal = null;

            if (type == "Cat")
            {
                animal = new Cat(name, energy, happiness, procedureTime);
            }
            if (type == "Dog")
            {
                animal = new Dog(name, energy, happiness, procedureTime);
            }
            if (type == "Lion")
            {
                animal = new Lion(name, energy, happiness, procedureTime);
            }
            if (type == "Pig")
            {
                animal = new Pig(name, energy, happiness, procedureTime);
            }

            if (!animals.ContainsKey(name))
            {
                animals.Add(name, animal);
                hotel.Accommodate(animal);

                return($"Animal {name} registered successfully");
            }
            else
            {
                throw new ArgumentException($"Animal {name} already exist");
            }
        }
Example #2
0
        public string RegisterAnimal(string type, string name, int energy, int happiness, int procedureTime)
        {
            try
            {
                if (type == "Cat")
                {
                    Cat cat = new Cat(name, energy, happiness, procedureTime);
                    Hotel.Accommodate(cat);
                    return($"Animal {name} registered successfully");
                }

                else if (type == "Dog")
                {
                    Dog dog = new Dog(name, energy, happiness, procedureTime);
                    Hotel.Accommodate(dog);
                    return($"Animal {name} registered successfully");
                }

                else if (type == "Lion")
                {
                    Lion lion = new Lion(name, energy, happiness, procedureTime);
                    Hotel.Accommodate(lion);
                    return($"Animal {name} registered successfully");
                }

                else
                {
                    Pig pig = new Pig(name, energy, happiness, procedureTime);
                    Hotel.Accommodate(pig);
                    return($"Animal {name} registered successfully");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }