Exemple #1
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "End")
            {
                var tokens  = input.Split();
                var command = tokens[0];
                var args    = tokens.Skip(1).ToArray();
                var result  = string.Empty;
                try
                {
                    switch (command)
                    {
                    case "RegisterAnimal":
                        string type          = args[0];
                        string name          = args[1];
                        int    energy        = int.Parse(args[2]);
                        int    happiness     = int.Parse(args[3]);
                        int    procedureTime = int.Parse(args[4]);
                        Console.WriteLine(animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime));
                        break;

                    case "Chip":
                        string name1          = args[0];
                        int    procedureTime1 = int.Parse(args[1]);
                        Console.WriteLine((animalCentre.Chip(name1, procedureTime1)));
                        break;

                    case "Vaccinate":
                        Console.WriteLine((animalCentre.Vaccinate(args[0], int.Parse(args[1]))));
                        break;

                    case "Fitness":
                        Console.WriteLine(animalCentre.Fitness(args[0], int.Parse(args[1])));
                        break;

                    case "Play":
                        Console.WriteLine(animalCentre.Play(args[0], int.Parse(args[1])));
                        break;

                    case "DentalCare":
                        Console.WriteLine(animalCentre.DentalCare(args[0], int.Parse(args[1])));
                        break;

                    case "NailTrim":
                        Console.WriteLine(animalCentre.NailTrim(args[0], int.Parse(args[1])));
                        break;

                    case "Adopt":
                        Console.WriteLine(animalCentre.Adopt(args[0], args[1]));
                        break;

                    case "History":
                        Console.WriteLine(animalCentre.History(args[0]));
                        break;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("InvalidOperationException: " + ex.Message);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("ArgumentException: " + ex.Message);
                }

                input = Console.ReadLine();
            }
            animalCentre.Print();
        }
Exemple #2
0
        public void Run()
        {
            var animalCentre = new AnimalCentre();

            string input = Console.ReadLine();

            while (input != "End")
            {
                var tokens        = input.Split();
                var procedureName = tokens[0];

                if (tokens[0] == "RegisterAnimal")
                {
                    var type          = tokens[1];
                    var name          = tokens[2];
                    var energy        = int.Parse(tokens[3]);
                    var happiness     = int.Parse(tokens[4]);
                    var proceduretime = int.Parse(tokens[5]);

                    try
                    {
                        Console.WriteLine(animalCentre.RegisterAnimal(type, name, energy, happiness, proceduretime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "Chip")
                {
                    var name          = tokens[1];
                    var procedureTime = int.Parse(tokens[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Chip(name, procedureTime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "Vaccinate")
                {
                    var name          = tokens[1];
                    var procedureTime = int.Parse(tokens[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Vaccinate(name, procedureTime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "Fitness")
                {
                    var name          = tokens[1];
                    var procedureTime = int.Parse(tokens[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Fitness(name, procedureTime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "Play")
                {
                    var name          = tokens[1];
                    var procedureTime = int.Parse(tokens[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Play(name, procedureTime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "DentalCare")
                {
                    var name          = tokens[1];
                    var procedureTime = int.Parse(tokens[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.DentalCare(name, procedureTime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "NailTrim")
                {
                    var name          = tokens[1];
                    var procedureTime = int.Parse(tokens[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.NailTrim(name, procedureTime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "Adopt")
                {
                    var name  = tokens[1];
                    var owner = tokens[2];

                    try
                    {
                        Console.WriteLine(animalCentre.Adopt(name, owner));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }

                else if (tokens[0] == "History")
                {
                    var procTime = tokens[1];

                    try
                    {
                        Console.WriteLine(animalCentre.History(procTime));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine("InvalidOperationException: " + e.Message);
                    }

                    catch (ArgumentException e)
                    {
                        Console.WriteLine("ArgumentException: " + e.Message);
                    }
                }
                input = Console.ReadLine();
            }

            animalCentre.Print();
        }