Exemple #1
0
        private static string CreateNewSpecificAnimal(string type)
        {
            switch (type)
            {
            case "Cat":
                Cat cat = new Cat(animalName, animalAge, animalGender);
                return(cat.ToString());

            case "Dog":
                Dog dog = new Dog(animalName, animalAge, animalGender);
                return(dog.ToString());

            case "Frog":
                Frog frog = new Frog(animalName, animalAge, animalGender);
                return(frog.ToString());

            case "Kitten":
                Kitten kitten = new Kitten(animalName, animalAge);
                return(kitten.ToString());

            case "Tomcat":
                Tomcat tomcat = new Tomcat(animalName, animalAge);
                return(tomcat.ToString());

            default:
                return(null);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    string animalType = Console.ReadLine();
                    if (animalType == "Beast!")
                    {
                        break;
                    }
                    string[] animalArgs = Console.ReadLine().Split();
                    switch (animalType)
                    {
                    case "Dog":
                        Dog dog = new Dog(animalArgs);
                        dog.GetTypeOfAnimal();
                        Console.WriteLine(dog.ToString());
                        dog.ProduceSound();
                        break;

                    case "Cat":
                        Cat cat = new Cat(animalArgs);
                        cat.GetTypeOfAnimal();
                        Console.WriteLine(cat.ToString());
                        cat.ProduceSound();
                        break;

                    case "Frog":
                        Frog frog = new Frog(animalArgs);
                        frog.GetTypeOfAnimal();
                        Console.WriteLine(frog.ToString());
                        frog.ProduceSound();
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(animalArgs);
                        kitten.GetTypeOfAnimal();
                        Console.WriteLine(kitten.ToString());
                        kitten.ProduceSound();
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(animalArgs);
                        tomcat.GetTypeOfAnimal();
                        Console.WriteLine(tomcat.ToString());
                        tomcat.ProduceSound();
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        public static void Main(string[] args)
        {
            string command = Console.ReadLine();

            while (command != "Beast!")
            {
                string[] tokens = Console.ReadLine().Split();

                if (tokens.Length == 3 &&
                    char.IsLetter(tokens[0][0]) &&
                    int.TryParse(tokens[1], out int x) &&
                    x >= 0 &&
                    (tokens[2].ToLower() == "male" || tokens[2] == "female"))
                {
                    string typeOfAnimal = command;

                    string name = tokens[0];
                    int    age  = int.Parse(tokens[1]);
                    string sex  = tokens[2];

                    if (typeOfAnimal == "Cat")
                    {
                        Cat cat = new Cat(name, age, sex);
                        Console.WriteLine(cat.ToString());
                    }
                    else if (typeOfAnimal == "Dog")
                    {
                        Dog dog = new Dog(name, age, sex);
                        Console.WriteLine(dog.ToString());
                    }
                    else if (typeOfAnimal == "Frog")
                    {
                        Frog frog = new Frog(name, age, sex);
                        Console.WriteLine(frog.ToString());
                    }
                    else if (typeOfAnimal == "Kitten")
                    {
                        Kitten kitten = new Kitten(name, age);
                        Console.WriteLine(kitten.ToString());
                    }
                    else if (typeOfAnimal == "Tomcat")
                    {
                        Tomcat tomcat = new Tomcat(name, age);
                        Console.WriteLine(tomcat.ToString());
                    }
                }
                else
                {
                    Console.WriteLine("Invalid input!");
                }

                command = Console.ReadLine();
            }
        }
Exemple #4
0
        public static void Main(string[] args)
        {
            string type;

            while ((type = Console.ReadLine()) != "Beast!")
            {
                string comand = Console.ReadLine();

                var comandArgs = comand.Split();
                var name       = comandArgs[0];
                var age        = int.Parse(comandArgs[1]);
                var gender     = comandArgs[2];

                if (name == "" || age < 0 || gender == "")
                {
                    Console.WriteLine("Invalid input!");
                }

                if (type == "Dog")
                {
                    Dog dog = new Dog(name, age, gender);
                    Console.WriteLine(dog.ToString());
                    dog.ProduceSound();
                }
                else if (type == "Cat")
                {
                    Cat cat = new Cat(name, age, gender);
                    Console.WriteLine(cat.ToString());
                    cat.ProduceSound();
                }
                else if (type == "Frog")
                {
                    Frog frog = new Frog(name, age, gender);
                    Console.WriteLine(frog.ToString());
                    frog.ProduceSound();
                }
                else if (type == "Kittens")
                {
                    Kitten kit = new Kitten(name, age);
                    Console.WriteLine(kit.ToString());
                    kit.ProduceSound();
                }
                else if (type == "Tomcat")
                {
                    Tomcat tom = new Tomcat(name, age);
                    Console.WriteLine(tom.ToString());
                    tom.ProduceSound();
                }
            }
        }
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            while (input != "Beast!")
            {
                try
                {
                    var tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                    switch (input)
                    {
                    case "Dog":
                        Dog dog = new Dog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                        Console.WriteLine(dog.ToString());
                        break;

                    case "Frog":
                        Frog frog = new Frog(tokens[0], int.Parse(tokens[1]), tokens[2]);
                        Console.WriteLine(frog.ToString());
                        break;

                    case "Cat":
                        Cat cat = new Cat(tokens[0], int.Parse(tokens[1]), tokens[2]);
                        Console.WriteLine(cat.ToString());
                        break;

                    case "Kitten":
                        Kitten kitten = new Kitten(tokens[0], int.Parse(tokens[1]));
                        Console.WriteLine(kitten.ToString());
                        break;

                    case "Tomcat":
                        Tomcat tomcat = new Tomcat(tokens[0], int.Parse(tokens[1]));
                        Console.WriteLine(tomcat.ToString());
                        break;

                    default:
                        throw new ArgumentException("Invalid input!");
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                input = Console.ReadLine();
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            string type;

            Animal animal;

            while ((type = Console.ReadLine()) != "Beast!")
            {
                string[] animalData = Console.ReadLine()
                                      .Split(" ")
                                      .ToArray();
                string name   = animalData[0];
                int    age    = int.Parse(animalData[1]);
                string gender = animalData[2];

                if (type == "Cat")
                {
                    try
                    {
                        animal = new Cat(name, age, gender);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (type == "Dog")
                {
                    try
                    {
                        animal = new Dog(name, age, gender);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (type == "Frog")
                {
                    try
                    {
                        animal = new Frog(name, age, gender);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (type == "Tomcat")
                {
                    try
                    {
                        animal = new Tomcat(name, age);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (type == "Kitten")
                {
                    try
                    {
                        animal = new Kitten(name, age);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
        public static void Main(string[] args)
        {
            string type = string.Empty;

            Animal animal;

            while ((type = Console.ReadLine()) != "Beast!")
            {
                string[] animalInfo = Console
                                      .ReadLine()
                                      .Split(" ")
                                      .ToArray();

                string name   = animalInfo[0];
                int    age    = int.Parse(animalInfo[1]);
                string gender = animalInfo[2];

                switch (type)
                {
                case "Dog":
                    try
                    {
                        animal = new Dog(name, age, gender);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Cat":
                    try
                    {
                        animal = new Cat(name, age, gender);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Frog":
                    try
                    {
                        animal = new Frog(name, age, gender);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Kittens":
                    try
                    {
                        animal = new Kitten(name, age);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "Tomcat":
                    try
                    {
                        animal = new Tomcat(name, age);
                        Console.WriteLine(animal.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;
                }
            }
        }