Пример #1
0
        public string Execute(string[] input)
        {
            switch (input[0])
            {
            case "RegisterAnimal":
                return(center.RegisterAnimal(input[1], input[2], int.Parse(input[3]), int.Parse(input[4]), int.Parse(input[5])));

            case "Chip":
                return(center.Chip(input[1], int.Parse(input[2])));

            case "Adopt":
                return(center.Adopt(input[1], input[2]));

            case "DentalCare":
                return(center.DentalCare(input[1], int.Parse(input[2])));

            case "Fitness":
                return(center.Fitness(input[1], int.Parse(input[2])));

            case "History":
                return(center.History(input[1]));

            case "NailTrim":
                return(center.NailTrim(input[1], int.Parse(input[2])));

            case "Play":
                return(center.Play(input[1], int.Parse(input[2])));

            case "Vaccinate":
                return(center.Vaccinate(input[1], int.Parse(input[2])));
            }

            return(INVALID_Command);
        }
Пример #2
0
        private void Vaccinate(string[] args)
        {
            string name          = args[1];
            int    procedureTime = int.Parse(args[2]);

            Console.WriteLine(animalCentre.Vaccinate(name, procedureTime));
        }
Пример #3
0
        private string ParseCommand(string[] data)
        {
            string commandType   = data[0];
            int    procedureTime = 0;
            string name          = "";

            switch (commandType)
            {
            case "RegisterAnimal":
                string type = data[1];
                name = data[2];
                int energy    = int.Parse(data[3]);
                int happiness = int.Parse(data[4]);
                procedureTime = int.Parse(data[5]);
                return(animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime));

            case "Chip":
                name          = data[1];
                procedureTime = int.Parse(data[2]);
                return(animalCentre.Chip(name, procedureTime));

            case "Vaccinate":
                name          = data[1];
                procedureTime = int.Parse(data[2]);
                return(animalCentre.Vaccinate(name, procedureTime));

            case "Fitness":
                name          = data[1];
                procedureTime = int.Parse(data[2]);
                return(animalCentre.Fitness(name, procedureTime));

            case "Play":
                name          = data[1];
                procedureTime = int.Parse(data[2]);
                return(animalCentre.Play(name, procedureTime));

            case "DentalCare":
                name          = data[1];
                procedureTime = int.Parse(data[2]);
                return(animalCentre.DentalCare(name, procedureTime));

            case "NailTrim":
                name          = data[1];
                procedureTime = int.Parse(data[2]);
                return(animalCentre.NailTrim(name, procedureTime));

            case "Adopt":
                name = data[1];
                string owner = data[2];
                return(animalCentre.Adopt(name, owner));

            case "History":
                string procedureType = data[1];
                return(animalCentre.History(procedureType));

            default:
                throw new ArgumentException("Invalid command type!");
            }
        }
Пример #4
0
        private void Read(string inputLine)
        {
            var args    = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var command = args[0];
            var result  = string.Empty;

            switch (command)
            {
            case "RegisterAnimal":
                result = animalCenter.RegisterAnimal(args[1], args[2], int.Parse(args[3]),
                                                     int.Parse(args[4]), int.Parse(args[5]));
                break;

            case "Chip":
                result = animalCenter.Chip(args[1], int.Parse(args[2]));
                break;

            case "Fitness":
                result = animalCenter.Fitness(args[1], int.Parse(args[2]));
                break;

            case "Vaccinate":
                result = animalCenter.Vaccinate(args[1], int.Parse(args[2]));
                break;

            case "Play":
                result = animalCenter.Play(args[1], int.Parse(args[2]));
                break;

            case "DentalCare":
                result = animalCenter.DentalCare(args[1], int.Parse(args[2]));
                break;

            case "NailTrim":
                result = animalCenter.NailTrim(args[1], int.Parse(args[2]));
                break;

            case "Adopt":
                result = animalCenter.Adopt(args[1], args[2]);
                break;

            case "History":
                result = animalCenter.History(args[1]);
                break;

            default:
                break;
            }

            outputMessage.AppendLine(result);
        }
Пример #5
0
        public void MoveCommand(string inputLine, AnimalCentre ac)
        {
            string[] input   = inputLine.Split();
            string   command = input[0];

            switch (command)
            {
            case "RegisterAnimal":
                Console.WriteLine(ac.RegisterAnimal(input[1], input[2], int.Parse(input[3]), int.Parse(input[4]), int.Parse(input[5]))); break;

            case "Chip":
                Console.WriteLine(ac.Chip(input[1], int.Parse(input[2]))); break;

            case "Vaccinate":
                Console.WriteLine(ac.Vaccinate(input[1], int.Parse(input[2]))); break;

            case "Fitness":
                Console.WriteLine(ac.Fitness(input[1], int.Parse(input[2]))); break;

            case "Play":
                Console.WriteLine(ac.Play(input[1], int.Parse(input[2]))); break;

            case "DentalCare":
                Console.WriteLine(ac.DentalCare(input[1], int.Parse(input[2]))); break;

            case "NailTrim":
                Console.WriteLine(ac.NailTrim(input[1], int.Parse(input[2]))); break;

            case "Adopt":
                string animalName = input[1];
                string owner      = input[2];

                Console.WriteLine(ac.Adopt(animalName, owner));

                if (!this.ownerAnimals.ContainsKey(owner))
                {
                    this.ownerAnimals[owner] = new List <string>();
                }

                this.ownerAnimals[owner].Add(animalName);

                break;

            case "History":
                Console.WriteLine(ac.History(input[1])); break;

            default: break;
            }
        }
Пример #6
0
        private void Execute(string command, string[] commandArgs)
        {
            switch (command)
            {
            case "RegisterAnimal":
                Console.WriteLine(animalCentre.RegisterAnimal(commandArgs[0], commandArgs[1], int.Parse(commandArgs[2]), int.Parse(commandArgs[3]), int.Parse(commandArgs[4])));
                break;

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

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

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

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

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

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

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

            case "History":
                Console.WriteLine(animalCentre.History(commandArgs[0]));
                break;

            default:
                break;
            }
        }
Пример #7
0
        private string ReadCommand(string command, string[] argumets)
        {
            Queue <string> line = new Queue <string>(argumets);
            string         typeAnimal;
            string         name;
            int            energy;
            int            happiness;
            int            procedureTime;
            string         owner;
            string         historyType;

            switch (command)
            {
            case "RegisterAnimal":
                typeAnimal    = line.Dequeue();
                name          = line.Dequeue();
                energy        = int.Parse(line.Dequeue());
                happiness     = int.Parse(line.Dequeue());
                procedureTime = int.Parse(line.Dequeue());
                return(zoo.RegisterAnimal(typeAnimal, name, energy, happiness, procedureTime));

                break;

            case "Chip":
                name          = line.Dequeue();
                procedureTime = int.Parse(line.Dequeue());
                return(zoo.Chip(name, procedureTime));

                break;

            case "Vaccinate":
                name          = line.Dequeue();
                procedureTime = int.Parse(line.Dequeue());
                return(zoo.Vaccinate(name, procedureTime));

                break;

            case "Fitness":
                name          = line.Dequeue();
                procedureTime = int.Parse(line.Dequeue());
                return(zoo.Fitness(name, procedureTime));

                break;

            case "Play":
                name          = line.Dequeue();
                procedureTime = int.Parse(line.Dequeue());
                return(zoo.Play(name, procedureTime));

                break;

            case "DentalCare":
                name          = line.Dequeue();
                procedureTime = int.Parse(line.Dequeue());
                return(zoo.DentalCare(name, procedureTime));

                break;

            case "NailTrim":
                name          = line.Dequeue();
                procedureTime = int.Parse(line.Dequeue());
                return(zoo.NailTrim(name, procedureTime));

                break;

            case "Adopt":
                name  = line.Dequeue();
                owner = line.Dequeue();
                return(zoo.Adopt(name, owner));

                break;

            case "History":
                historyType = line.Dequeue();
                return(zoo.History(historyType));

                break;

            default:
                return("Wrong input");

                break;
            }
        }
Пример #8
0
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                string[] args    = input.Split();
                string   command = args[0];

                string result = string.Empty;
                try
                {
                    switch (command)
                    {
                    case "RegisterAnimal":
                        string type          = args[1];
                        string name          = args[2];
                        int    energy        = int.Parse(args[3]);
                        int    happiness     = int.Parse(args[4]);
                        int    procedureTime = int.Parse(args[5]);
                        result = animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime);
                        break;

                    case "Chip":
                        string namechip          = args[1];
                        int    procedureTimeChip = int.Parse(args[2]);
                        result = animalCentre.Chip(namechip, procedureTimeChip);
                        break;

                    case "Vaccinate":
                        string nameVaccinate          = args[1];
                        int    procedureTimeVaccinate = int.Parse(args[2]);
                        result = animalCentre.Vaccinate(nameVaccinate, procedureTimeVaccinate);
                        break;

                    case "Fitness":
                        string nameFitness          = args[1];
                        int    procedureTimeFitness = int.Parse(args[2]);
                        result = animalCentre.Fitness(nameFitness, procedureTimeFitness);
                        break;

                    case "Play":
                        string namePlay          = args[1];
                        int    procedureTimePlay = int.Parse(args[2]);
                        result = animalCentre.Play(namePlay, procedureTimePlay);
                        break;

                    case "DentalCare":
                        string nameDentalCare          = args[1];
                        int    procedureTimeDentalCare = int.Parse(args[2]);
                        result = animalCentre.DentalCare(nameDentalCare, procedureTimeDentalCare);
                        break;

                    case "NailTrim":
                        string nameNailTrim          = args[1];
                        int    procedureTimeNailTrim = int.Parse(args[2]);
                        result = animalCentre.NailTrim(nameNailTrim, procedureTimeNailTrim);
                        break;

                    case "Adopt":
                        string animalName = args[1];
                        string owner      = args[2];
                        result = animalCentre.Adopt(animalName, owner);
                        if (!adoptedAnimals.ContainsKey(owner))
                        {
                            adoptedAnimals.Add(owner, new List <string>());
                            adoptedAnimals[owner].Add(animalName);
                        }
                        else
                        {
                            adoptedAnimals[owner].Add(animalName);
                        }
                        break;

                    case "History":
                        string procedureType = args[1];
                        result = animalCentre.History(procedureType);
                        break;

                    default:
                        break;
                    }

                    Console.WriteLine(result);
                }
                catch (InvalidOperationException x)
                {
                    Console.WriteLine("InvalidOperationException: " + x.Message);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine("ArgumentException: " + ae.Message);
                }
            }

            foreach (var item in adoptedAnimals.OrderBy(x => x.Key))
            {
                Console.WriteLine($"--Owner: {item.Key}");

                Console.WriteLine($"    - Adopted animals: {string.Join(" ", item.Value)}");
            }
        }
Пример #9
0
        public void Run()
        {
            string hold = Console.ReadLine();

            while (hold != "End")
            {
                string[] comands = hold.Split();
                string   type    = comands[0];

                try
                {
                    if (type == "RegisterAnimal")
                    {
                        Console.WriteLine(animalCentre.RegisterAnimal(comands[1], comands[2], int.Parse(comands[3]), int.Parse(comands[4]), int.Parse(comands[5])));
                    }
                    else if (type == "Chip")
                    {
                        Console.WriteLine(animalCentre.Chip(comands[1], int.Parse(comands[2])));
                    }
                    else if (type == "Vaccinate")
                    {
                        Console.WriteLine(animalCentre.Vaccinate(comands[1], int.Parse(comands[2])));
                    }
                    else if (type == "Fitness")
                    {
                        Console.WriteLine(animalCentre.Fitness(comands[1], int.Parse(comands[2])));
                    }
                    else if (type == "Play")
                    {
                        Console.WriteLine(animalCentre.Play(comands[1], int.Parse(comands[2])));
                    }
                    else if (type == "DentalCare")
                    {
                        Console.WriteLine(animalCentre.DentalCare(comands[1], int.Parse(comands[2])));
                    }
                    else if (type == "NailTrim")
                    {
                        Console.WriteLine(animalCentre.NailTrim(comands[1], int.Parse(comands[2])));
                    }
                    else if (type == "Adopt")
                    {
                        Console.WriteLine(animalCentre.Adopt(comands[1], comands[2]));
                    }
                    else if (type == "History")
                    {
                        Console.WriteLine(comands[1]);
                        string result = animalCentre.History(comands[1]);
                        Console.WriteLine(result);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine($"InvalidOperationException: {ex.Message}");
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine($"ArgumentException: {ex.Message}");
                }

                hold = Console.ReadLine();
            }

            Dictionary <string, List <IAnimal> > adopted = new Dictionary <string, List <IAnimal> >(animalCentre.adoptedStuff);

            foreach (var item in adopted.OrderBy(x => x.Key))
            {
                Console.WriteLine($"--Owner: {item.Key}");
                Console.Write("    - Adopted animals: ");
                foreach (var curentAnimal in item.Value)
                {
                    Console.Write($"{curentAnimal.Name} ");
                }

                Console.WriteLine();
            }
        }
Пример #10
0
        public void Run()
        {
            string[] inputArgs = Console.ReadLine().Split();

            while (inputArgs[0] != "End")
            {
                try
                {
                    switch (inputArgs[0])
                    {
                    case "RegisterAnimal":
                        string type         = inputArgs[1];
                        string name         = inputArgs[2];
                        int    energy       = int.Parse(inputArgs[3]);
                        int    hapiness     = int.Parse(inputArgs[4]);
                        int    procedurTime = int.Parse(inputArgs[5]);

                        string result = animalCentre.RegisterAnimal(type, name, energy, hapiness, procedurTime);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "Chip":
                        name         = inputArgs[1];
                        procedurTime = int.Parse(inputArgs[2]);
                        result       = animalCentre.Chip(name, procedurTime);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "Vaccinate":
                        name         = inputArgs[1];
                        procedurTime = int.Parse(inputArgs[2]);
                        result       = animalCentre.Vaccinate(name, procedurTime);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "Fitness":
                        name         = inputArgs[1];
                        procedurTime = int.Parse(inputArgs[2]);
                        result       = animalCentre.Fitness(name, procedurTime);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "Play":
                        name         = inputArgs[1];
                        procedurTime = int.Parse(inputArgs[2]);
                        result       = animalCentre.Play(name, procedurTime);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "DentalCare":
                        name         = inputArgs[1];
                        procedurTime = int.Parse(inputArgs[2]);
                        result       = animalCentre.DentalCare(name, procedurTime);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "NailTrim":
                        name         = inputArgs[1];
                        procedurTime = int.Parse(inputArgs[2]);
                        result       = animalCentre.NailTrim(name, procedurTime);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "Adopt":
                        name = inputArgs[1];
                        string owner = inputArgs[2];
                        result = animalCentre.Adopt(name, owner);
                        Console.WriteLine(result);
                        result = "";
                        break;

                    case "History":
                        string procedureType = inputArgs[1];

                        result = animalCentre.History(procedureType);
                        Console.WriteLine(result);
                        result = "";
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"ArgumentException: {ae.Message}");
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"InvalidOperationException: {ioe.Message}");
                }

                inputArgs = Console.ReadLine().Split();
            }

            foreach (var owners in animalCentre.AnimalsInHotel.OrderBy(x => x.Owner))
            {
                Console.WriteLine($"--Owner: {owners.Owner}");
                Console.Write($"    - Adopted animals: ");
                List <string> adopAnimArr = new List <string>();
                foreach (var animalll in animalCentre.AnimalsInHotel.OrderBy(x => x.Name))
                {
                    adopAnimArr.Add(animalll.Name);
                }
                Console.WriteLine($"{string.Join(", ", adopAnimArr)}");
            }
        }
Пример #11
0
        public void Run()
        {
            string input = Console.ReadLine();


            while (input != "End")
            {
                try
                {
                    string[] tokens = input
                                      .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                    string command = tokens[0];

                    if (command == "RegisterAnimal")
                    {
                        string type          = tokens[1];
                        string name          = tokens[2];
                        int    energy        = int.Parse(tokens[3]);
                        int    happiness     = int.Parse(tokens[4]);
                        int    procedureTime = int.Parse(tokens[5]);

                        Console.WriteLine(animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime));
                    }
                    else if (command == "History")
                    {
                        string type = tokens[1];

                        Console.WriteLine(animalCentre.History(type));
                    }
                    else if (command == "Adopt")
                    {
                        string animalName = tokens[1];
                        string owner      = tokens[2];

                        Console.WriteLine(animalCentre.Adopt(animalName, owner));
                    }
                    else
                    {
                        string name = tokens[1];
                        int    time = int.Parse(tokens[2]);

                        if (command == "Vaccinate")
                        {
                            Console.WriteLine(animalCentre.Vaccinate(name, time));
                        }
                        else if (command == "Fitness")
                        {
                            Console.WriteLine(animalCentre.Fitness(name, time));
                        }
                        else if (command == "Play")
                        {
                            Console.WriteLine(animalCentre.Play(name, time));
                        }
                        else if (command == "DentalCare")
                        {
                            Console.WriteLine(animalCentre.DentalCare(name, time));
                        }
                        else if (command == "NailTrim")
                        {
                            Console.WriteLine(animalCentre.NailTrim(name, time));
                        }
                        else if (command == "Chip")
                        {
                            Console.WriteLine(animalCentre.Chip(name, time));
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"{e.GetType().Name}: {e.Message}");
                }

                input = Console.ReadLine();
            }

            Console.WriteLine(animalCentre.ShowAdoptedAnimals());
        }
Пример #12
0
        public void Run()
        {
            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                try
                {
                    string[] commandArgs = input.Split();

                    string command = commandArgs[0];
                    string name;
                    int    procedureTime;

                    switch (command)
                    {
                    case "RegisterAnimal":
                        string type = commandArgs[1];
                        name = commandArgs[2];
                        int energy    = int.Parse(commandArgs[3]);
                        int happiness = int.Parse(commandArgs[4]);
                        procedureTime = int.Parse(commandArgs[5]);
                        Console.WriteLine(ac.RegisterAnimal(type, name, energy, happiness, procedureTime));
                        break;

                    case "Chip":
                        name          = commandArgs[1];
                        procedureTime = int.Parse(commandArgs[2]);
                        Console.WriteLine(ac.Chip(name, procedureTime));
                        break;

                    case "Vaccinate":
                        name          = commandArgs[1];
                        procedureTime = int.Parse(commandArgs[2]);
                        Console.WriteLine(ac.Vaccinate(name, procedureTime));
                        break;

                    case "Fitness":
                        name          = commandArgs[1];
                        procedureTime = int.Parse(commandArgs[2]);
                        Console.WriteLine(ac.Fitness(name, procedureTime));
                        break;

                    case "Play":
                        name          = commandArgs[1];
                        procedureTime = int.Parse(commandArgs[2]);
                        Console.WriteLine(ac.Play(name, procedureTime));
                        break;

                    case "DentalCare":
                        name          = commandArgs[1];
                        procedureTime = int.Parse(commandArgs[2]);
                        Console.WriteLine(ac.DentalCare(name, procedureTime));
                        break;

                    case "NailTrim":
                        name          = commandArgs[1];
                        procedureTime = int.Parse(commandArgs[2]);
                        Console.WriteLine(ac.NailTrim(name, procedureTime));
                        break;

                    case "Adopt":
                        name = commandArgs[1];
                        string  owner  = commandArgs[2];
                        IAnimal animal = ac.GetAnimal(name);
                        Console.WriteLine(ac.Adopt(name, owner));


                        break;

                    case "History":
                        string procedureType = commandArgs[1];
                        Console.WriteLine(ac.History(procedureType));
                        break;

                    default:
                        break;
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"InvalidOperationException: {ioe.Message}");
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"ArgumentException: {ae.Message}");
                }
            }

            foreach (var owner in ac.AddoptedPets.OrderBy(o => o.Key))
            {
                Console.WriteLine($"--Owner: {owner.Key}");
                Console.WriteLine($"   - Adopted animals: {string.Join(" ", owner.Value.Select(a => a.Name))}");
            }
        }
Пример #13
0
        public void Run()
        {
            Hotel hotel = new Hotel();
            var   line  = Console.ReadLine()
                          .Split()
                          .ToList();

            var isRunning = true;

            command = line[0];

            AnimalCentre animalCentre = new AnimalCentre();

            while (isRunning)
            {
                string name = string.Empty;
                command = line[0];

                switch (command)
                {
                case "RegisterAnimal":
                    var type = line[1];
                    name = line[2];
                    var energy        = int.Parse(line[3]);
                    var happiness     = int.Parse(line[4]);
                    var procedureTime = int.Parse(line[5]);

                    try
                    {
                        Console.WriteLine(animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine("InvalidOperationException: " + ex.Message);
                    }
                    break;

                case "Chip":
                    name          = line[1];
                    procedureTime = int.Parse(line[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Chip(name, procedureTime));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    break;

                case "Vaccinate":
                    name          = line[1];
                    procedureTime = int.Parse(line[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Vaccinate(name, procedureTime));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    break;

                case "Fitness":
                    name          = line[1];
                    procedureTime = int.Parse(line[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Fitness(name, procedureTime));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    break;

                case "Play":
                    name          = line[1];
                    procedureTime = int.Parse(line[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.Play(name, procedureTime));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    break;

                case "DentalCare":
                    name          = line[1];
                    procedureTime = int.Parse(line[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.DentalCare(name, procedureTime));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    break;

                case "NailTrim":
                    name          = line[1];
                    procedureTime = int.Parse(line[2]);

                    try
                    {
                        Console.WriteLine(animalCentre.NailTrim(name, procedureTime));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    break;

                case "Adopt":
                    name = line[1];
                    var owner = line[2];

                    try
                    {
                        Console.WriteLine(animalCentre.Adopt(name, owner));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    break;

                case "History":
                    var procedureType = line[1];

                    try
                    {
                        Console.WriteLine(animalCentre.History(procedureType));
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine("ArgumentException: " + ex.Message);
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine("InvalidOperationException: " + ex.Message);
                    }
                    break;
                }

                line = Console.ReadLine()
                       .Split()
                       .ToList();

                if (line[0] == "End")
                {
                    isRunning = false;
                }
            }

            Console.WriteLine(animalCentre.PrintAdoptedAnimals());
        }
Пример #14
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "End")
            {
                string[] arguments = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   command   = arguments[0];
                string   output    = string.Empty;
                try
                {
                    switch (command)
                    {
                    case "RegisterAnimal":

                        string type          = arguments[1];
                        string name          = arguments[2];
                        int    energy        = int.Parse(arguments[3]);
                        int    happiness     = int.Parse(arguments[4]);
                        int    procedureTime = int.Parse(arguments[5]);
                        output = animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime);
                        break;

                    case "Chip":
                        string animalName       = arguments[1];
                        int    timeForProcedure = int.Parse(arguments[2]);
                        output = animalCentre.Chip(animalName, timeForProcedure);
                        break;

                    case "Vaccinate":
                        animalName       = arguments[1];
                        timeForProcedure = int.Parse(arguments[2]);
                        output           = animalCentre.Vaccinate(animalName, timeForProcedure);
                        break;

                    case "Fitness":
                        animalName       = arguments[1];
                        timeForProcedure = int.Parse(arguments[2]);
                        output           = animalCentre.Fitness(animalName, timeForProcedure);
                        break;

                    case "Play":
                        animalName       = arguments[1];
                        timeForProcedure = int.Parse(arguments[2]);
                        output           = animalCentre.Play(animalName, timeForProcedure);
                        break;

                    case "DentalCare":
                        animalName       = arguments[1];
                        timeForProcedure = int.Parse(arguments[2]);
                        output           = animalCentre.DentalCare(animalName, timeForProcedure);
                        break;

                    case "NailTrim":
                        animalName       = arguments[1];
                        timeForProcedure = int.Parse(arguments[2]);
                        output           = animalCentre.NailTrim(animalName, timeForProcedure);
                        break;

                    case "Adopt":
                        animalName = arguments[1];
                        string owner = arguments[2];
                        output = animalCentre.Adopt(animalName, owner);
                        break;

                    case "History":
                        string procedureType = arguments[1];
                        output = animalCentre.History(procedureType);
                        break;

                    default:
                        break;
                    }

                    Console.WriteLine(output);
                }
                catch (InvalidOperationException oe)
                {
                    Console.WriteLine("InvalidOperationException: " + oe.Message);
                }
                catch (ArgumentException oe)
                {
                    Console.WriteLine("ArgumentException: " + oe.Message);
                }

                input = Console.ReadLine();
            }

            var           adoptedAnimalsCollestion = this.animalCentre.AdoptedAnimals;
            StringBuilder sb = new StringBuilder();

            foreach (var owner in adoptedAnimalsCollestion.OrderBy(x => x.Key))
            {
                sb.AppendLine($"--Owner: {owner.Key}");
                sb.Append($"    - Adopted animals: ");
                foreach (var item in owner.Value)
                {
                    sb.Append(item.Name + " ");
                }
                sb.AppendLine();
            }

            Console.WriteLine(sb.ToString().TrimEnd());
        }
Пример #15
0
        public void Run()
        {
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                string   commandType = command.Split()[0];
                string[] commandArgs = command.Split().Skip(1).ToArray();

                try
                {
                    string result;

                    switch (commandType)
                    {
                    case "RegisterAnimal":
                        result = animalCentre.RegisterAnimal(commandArgs[0], commandArgs[1],
                                                             int.Parse(commandArgs[2]), int.Parse(commandArgs[3]), int.Parse(commandArgs[4]));
                        break;

                    case "Chip":
                        result = animalCentre.Chip(commandArgs[0], int.Parse(commandArgs[1]));
                        break;

                    case "Vaccinate":
                        result = animalCentre.Vaccinate(commandArgs[0], int.Parse(commandArgs[1]));
                        break;

                    case "Fitness":
                        result = animalCentre.Fitness(commandArgs[0], int.Parse(commandArgs[1]));
                        break;

                    case "Play":
                        result = animalCentre.Play(commandArgs[0], int.Parse(commandArgs[1]));
                        break;

                    case "DentalCare":
                        result = animalCentre.DentalCare(commandArgs[0], int.Parse(commandArgs[1]));
                        break;

                    case "NailTrim":
                        result = animalCentre.NailTrim(commandArgs[0], int.Parse(commandArgs[1]));
                        break;

                    case "Adopt":
                        result = animalCentre.Adopt(commandArgs[0], commandArgs[1]);
                        break;

                    case "History":
                        result = animalCentre.History(commandArgs[0]);
                        break;

                    default:
                        result = null;
                        break;
                    }

                    Print(result);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine($"InvalidOperationException: {ex.Message}");
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine($"ArgumentException: {ex.Message}");
                }
            }

            this.isRunning = false;

            StringBuilder sb = new StringBuilder();

            foreach (var kvp in animalCentre.adoptedAnimals.OrderBy(x => x.Key))
            {
                sb.AppendLine($"--Owner: {kvp.Key}");

                List <string> animalNames = new List <string>();

                foreach (var animal in kvp.Value)
                {
                    animalNames.Add(animal.Name);
                }
                sb.AppendLine($"    - Adopted animals: {string.Join(" ", animalNames)}");
            }

            string finalResult = sb.ToString();

            Console.WriteLine(finalResult);
        }
Пример #16
0
        public void Run()
        {
            string[] inputArgs = Console.ReadLine()
                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();

            string command       = inputArgs[0].ToLower();
            string type          = string.Empty;
            string name          = string.Empty;
            string owner         = string.Empty;
            string procedureType = string.Empty;
            int    energy        = 0;
            int    happiness     = 0;
            int    procedureTime = 0;
            string output        = string.Empty;

            while (command != "end")
            {
                try
                {
                    switch (command)
                    {
                    case "registeranimal":
                        type          = inputArgs[1];
                        name          = inputArgs[2];
                        energy        = int.Parse(inputArgs[3]);
                        happiness     = int.Parse(inputArgs[4]);
                        procedureTime = int.Parse(inputArgs[5]);
                        output        = animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime);
                        break;

                    case "chip":
                        name          = inputArgs[1];
                        procedureTime = int.Parse(inputArgs[2]);
                        output        = animalCentre.Chip(name, procedureTime);
                        break;

                    case "vaccinate":
                        name          = inputArgs[1];
                        procedureTime = int.Parse(inputArgs[2]);
                        output        = animalCentre.Vaccinate(name, procedureTime);
                        break;

                    case "fitness":
                        name          = inputArgs[1];
                        procedureTime = int.Parse(inputArgs[2]);
                        output        = animalCentre.Fitness(name, procedureTime);
                        break;

                    case "play":
                        name          = inputArgs[1];
                        procedureTime = int.Parse(inputArgs[2]);
                        output        = animalCentre.Play(name, procedureTime);
                        break;

                    case "dentalcare":
                        name          = inputArgs[1];
                        procedureTime = int.Parse(inputArgs[2]);
                        output        = animalCentre.DentalCare(name, procedureTime);
                        break;

                    case "nailtrim":
                        name          = inputArgs[1];
                        procedureTime = int.Parse(inputArgs[2]);
                        output        = animalCentre.NailTrim(name, procedureTime);
                        break;

                    case "adopt":
                        name   = inputArgs[1];
                        owner  = inputArgs[2];
                        output = animalCentre.Adopt(name, owner);
                        break;

                    case "history":
                        procedureType = inputArgs[1];
                        output        = animalCentre.History(procedureType);
                        break;

                    default:
                        throw new ArgumentException("Invalid command");
                    }
                    Console.WriteLine(output);
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine($"InvalidOperationException: {e.Message}");
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine($"ArgumentException: {e.Message}");
                }
                inputArgs = Console.ReadLine()
                            .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                            .ToArray();
                command = inputArgs[0].ToLower();
            }

            //foreach (var animal in pro)
            //{
            //    Console.WriteLine($"--Owner: {animal.Value.Owner}");
            //    Console.WriteLine($"    - Adopted animals: {animal.Value}");
            //}
        }
Пример #17
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();
        }
Пример #18
0
        public void Run()
        {
            var AnimalCentre = new AnimalCentre();

            while (true)
            {
                string[] inputArgs = Console.ReadLine().Split();
                if (inputArgs[0] == "End")
                {
                    break;
                }

                string[] arguments = inputArgs.Skip(1).ToArray();

                try
                {
                    switch (inputArgs[0])
                    {
                    case "RegisterAnimal":
                        Console.WriteLine(AnimalCentre.RegisterAnimal(arguments[0], arguments[1], int.Parse(arguments[2]), int.Parse(arguments[3]), int.Parse(arguments[4])));
                        break;

                    case "Chip":
                        Console.WriteLine(AnimalCentre.Chip(arguments[0], int.Parse(arguments[1])));
                        break;

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

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

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

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

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

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

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

            var sortedAopted = AnimalCentre.adopted.OrderBy(x => x.Key);

            foreach (var name in sortedAopted)
            {
                Console.WriteLine($"--Owner: {name.Key}");
                Console.Write("    - Adopted animals: ");
                foreach (var animal in name.Value)
                {
                    Console.Write(animal.Name + " ");
                }
                Console.WriteLine();
            }
        }
Пример #19
0
        public void Run()
        {
            string line = Console.ReadLine();

            while (line != "End")
            {
                string[] tokens = line.Split();

                string command = tokens[0];

                string output = string.Empty;

                if (command == "RegisterAnimal")
                {
                    string type          = tokens[1];
                    string name          = tokens[2];
                    int    energy        = int.Parse(tokens[3]);
                    int    hapiness      = int.Parse(tokens[4]);
                    int    procedureTime = int.Parse(tokens[5]);

                    try
                    {
                        output = animalCenter.RegisterAnimal(type, name, energy, hapiness, procedureTime);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }
                else if (command == "Chip")
                {
                    try
                    {
                        string name = tokens[1];
                        int    time = int.Parse(tokens[2]);

                        output = animalCenter.Chip(name, time);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }
                else if (command == "Vaccinate")
                {
                    try
                    {
                        string name = tokens[1];
                        int    time = int.Parse(tokens[2]);

                        output = animalCenter.Vaccinate(name, time);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }
                else if (command == "Fitness")
                {
                    try
                    {
                        string name = tokens[1];
                        int    time = int.Parse(tokens[2]);

                        output = animalCenter.Fitness(name, time);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }

                else if (command == "Play")
                {
                    try
                    {
                        string name = tokens[1];
                        int    time = int.Parse(tokens[2]);

                        output = animalCenter.Play(name, time);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }
                else if (command == "DentalCare")
                {
                    try
                    {
                        string name = tokens[1];
                        int    time = int.Parse(tokens[2]);

                        output = animalCenter.DentalCare(name, time);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }
                else if (command == "NailTrim")
                {
                    try
                    {
                        string name = tokens[1];
                        int    time = int.Parse(tokens[2]);

                        output = animalCenter.NailTrim(name, time);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }
                else if (command == "Adopt")
                {
                    try
                    {
                        string name  = tokens[1];
                        string owner = tokens[2];

                        output = animalCenter.Adopt(name, owner);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }

                else if (command == "History")
                {
                    try
                    {
                        string procedure = tokens[1];

                        output = animalCenter.History(procedure);
                    }
                    catch (ArgumentException ex)
                    {
                        output = ex.Message;
                    }
                    catch (InvalidOperationException ex)
                    {
                        output = ex.Message;
                    }
                }

                if (!string.IsNullOrEmpty(output))
                {
                    Console.WriteLine(output);
                }

                line = Console.ReadLine();
            }

            if (animalCenter.owners.Count > 0)
            {
                foreach (var kvp in animalCenter.owners?.OrderBy(x => x.Key))
                {
                    Console.WriteLine($"--Owner: {kvp.Key}");
                    if (kvp.Value.Count > 0)
                    {
                        Console.WriteLine($"    - Adopted animals: {string.Join(" ", kvp.Value?.Select(x => $"{x?.Name}"))}");
                    }
                }
            }
        }
Пример #20
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();
        }
Пример #21
0
        public void Run()
        {
            this.isRunning = true;

            while (this.isRunning)
            {
                string   input   = Console.ReadLine();
                string[] tokens  = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   command = tokens[0];
                string   name;
                int      procedureTime;
                string   output = "";

                try
                {
                    switch (command)
                    {
                    case "RegisterAnimal":
                        string type = tokens[1];
                        name = tokens[2];
                        int energy    = int.Parse(tokens[3]);
                        int happiness = int.Parse(tokens[4]);
                        procedureTime = int.Parse(tokens[5]);
                        output        = animalCentre.RegisterAnimal(type, name, energy,
                                                                    happiness, procedureTime);
                        break;

                    case "Chip":
                        name          = tokens[1];
                        procedureTime = int.Parse(tokens[2]);
                        output        = animalCentre.Chip(name, procedureTime);
                        break;

                    case "Vaccinate":
                        name          = tokens[1];
                        procedureTime = int.Parse(tokens[2]);
                        output        = animalCentre.Vaccinate(name, procedureTime);
                        break;

                    case "Fitness":
                        name          = tokens[1];
                        procedureTime = int.Parse(tokens[2]);
                        output        = animalCentre.Fitness(name, procedureTime);
                        break;

                    case "Play":
                        name          = tokens[1];
                        procedureTime = int.Parse(tokens[2]);
                        output        = animalCentre.Play(name, procedureTime);
                        break;

                    case "DentalCare":
                        name          = tokens[1];
                        procedureTime = int.Parse(tokens[2]);
                        output        = animalCentre.DentalCare(name, procedureTime);
                        break;

                    case "NailTrim":
                        name          = tokens[1];
                        procedureTime = int.Parse(tokens[2]);
                        output        = animalCentre.NailTrim(name, procedureTime);
                        break;

                    case "Adopt":
                        name = tokens[1];
                        string owner = tokens[2];
                        output = animalCentre.Adopt(name, owner);
                        if (!owners.ContainsKey(owner))
                        {
                            owners.Add(owner, new List <string>());
                        }
                        owners[owner].Add(name);
                        break;

                    case "History":
                        string procedureType = tokens[1];
                        output = animalCentre.History(procedureType);
                        break;

                    case "End":
                        this.isRunning = false;
                        output         = Print();
                        break;
                    }
                }
                catch (InvalidOperationException ioex)
                {
                    output = $"InvalidOperationException: {ioex.Message}";
                }
                catch (ArgumentException aex)
                {
                    output = $"ArgumentException: {aex.Message}";
                }
                Console.WriteLine(output);
                debug.Append(output + Environment.NewLine);
            }

            //Console.WriteLine("_________________________________");
            //Console.WriteLine(debug.ToString());
        }
Пример #22
0
        private string RunCommand(string[] args)
        {
            var    command = args[0];
            string type    = args[1];
            string name    = args[1];
            int    procedureTime;

            switch (command)
            {
            //•	RegisterAnimal {type} {name} {energy} {happiness} {procedureTime}
            //•	Chip {name} {procedureTime}
            //•	Vaccinate {name} {procedureTime}
            //•	Fitness {name} {procedureTime}
            //•	Play {name} {procedureTime}
            //•	DentalCare {name} {procedureTime}
            //•	NailTrim {name} {procedureTime}
            //•	Adopt {animal name} {owner}
            //•	History {procedureType}

            case "RegisterAnimal":
                name = args[2];
                int energy    = int.Parse(args[3]);
                int happiness = int.Parse(args[4]);
                procedureTime = int.Parse(args[5]);
                return(animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime));

            case "Chip":
                procedureTime = int.Parse(args[2]);
                return(animalCentre.Chip(name, procedureTime));

            case "Vaccinate":
                procedureTime = int.Parse(args[2]);
                return(animalCentre.Vaccinate(name, procedureTime));

            case "Fitness":
                procedureTime = int.Parse(args[2]);
                return(animalCentre.Fitness(name, procedureTime));

            case "Play":
                procedureTime = int.Parse(args[2]);
                return(animalCentre.Play(name, procedureTime));

            case "DentalCare":
                procedureTime = int.Parse(args[2]);
                return(animalCentre.DentalCare(name, procedureTime));

            case "NailTrim":
                procedureTime = int.Parse(args[2]);
                return(animalCentre.NailTrim(name, procedureTime));

            case "Adopt":
                string owner = args[2];
                return(animalCentre.Adopt(name, owner));

            case "History":
                return(animalCentre.History(name));

            default:
                throw new InvalidOperationException("Invalid command");
            }
        }
Пример #23
0
        public static void Run()
        {
            var args         = Console.ReadLine().Split();
            var animalCentre = new AnimalCentre();
            var result       = string.Empty;

            while (args[0] != "End")
            {
                var command = args[0];
                try
                {
                    switch (command)
                    {
                    case "RegisterAnimal":
                    {
                        var type          = args[1];
                        var name          = args[2];
                        var energy        = int.Parse(args[3]);
                        var happiness     = int.Parse(args[4]);
                        var procedureTime = int.Parse(args[5]);
                        result = animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime);
                    }
                    break;

                    case "Chip":
                    {
                        var name          = args[1];
                        var procedureTime = int.Parse(args[2]);
                        result = animalCentre.Chip(name, procedureTime);
                    }
                    break;

                    case "Vaccinate":
                    {
                        var name          = args[1];
                        var procedureTime = int.Parse(args[2]);
                        result = animalCentre.Vaccinate(name, procedureTime);
                    }
                    break;

                    case "Fitness":
                    {
                        var name          = args[1];
                        var procedureTime = int.Parse(args[2]);
                        result = animalCentre.Fitness(name, procedureTime);
                    }
                    break;

                    case "Play":
                    {
                        var name          = args[1];
                        var procedureTime = int.Parse(args[2]);
                        result = animalCentre.Play(name, procedureTime);
                    }
                    break;

                    case "DentalCare":
                    {
                        var name          = args[1];
                        var procedureTime = int.Parse(args[2]);
                        result = animalCentre.DentalCare(name, procedureTime);
                    }
                    break;

                    case "NailTrim":
                    {
                        var name          = args[1];
                        var procedureTime = int.Parse(args[2]);
                        result = animalCentre.NailTrim(name, procedureTime);
                    }
                    break;

                    case "Adopt":
                    {
                        var name  = args[1];
                        var owner = args[2];
                        result = animalCentre.Adopt(name, owner);
                    }
                    break;

                    case "History":
                    {
                        var type = args[1];

                        result = animalCentre.History(type);
                    }
                    break;

                    default:
                        break;
                    }
                }
                catch (InvalidOperationException IOE)
                {
                    result = "InvalidOperationException: " + IOE.Message;
                }
                catch (ArgumentException AE)
                {
                    result = "ArgumentException: " + AE.Message;
                }
                Console.WriteLine(result);
                args = Console.ReadLine().Split();
            }

            foreach (var owner in animalCentre.Adopted.OrderBy(x => x.Key))
            {
                Console.WriteLine($"--Owner: {owner.Key}");
                Console.WriteLine($"    - Adopted animals: {string.Join(' ', owner.Value.Select(x => x.Name))}");
            }
        }
Пример #24
0
        private string CommandParser(string input)
        {
            string[] inputArgs = input.Split();

            string command = inputArgs[0];

            string output = string.Empty;

            switch (command)
            {
            case "RegisterAnimal":
                string type          = inputArgs[1];
                string name          = inputArgs[2];
                int    energy        = int.Parse(inputArgs[3]);
                int    happiness     = int.Parse(inputArgs[4]);
                int    procedureTime = int.Parse(inputArgs[5]);
                output = animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime);
                break;

            case "Chip":
                name          = inputArgs[1];
                procedureTime = int.Parse(inputArgs[2]);
                output        = animalCentre.Chip(name, procedureTime);
                break;

            case "Vaccinate":
                name          = inputArgs[1];
                procedureTime = int.Parse(inputArgs[2]);
                output        = animalCentre.Vaccinate(name, procedureTime);
                break;

            case "Fitness":
                name          = inputArgs[1];
                procedureTime = int.Parse(inputArgs[2]);
                output        = animalCentre.Fitness(name, procedureTime);
                break;

            case "Play":
                name          = inputArgs[1];
                procedureTime = int.Parse(inputArgs[2]);
                output        = animalCentre.Play(name, procedureTime);
                break;

            case "DentalCare":
                name          = inputArgs[1];
                procedureTime = int.Parse(inputArgs[2]);
                output        = animalCentre.DentalCare(name, procedureTime);
                break;

            case "NailTrim":
                name          = inputArgs[1];
                procedureTime = int.Parse(inputArgs[2]);
                output        = animalCentre.NailTrim(name, procedureTime);
                break;

            case "Adopt":
                name = inputArgs[1];
                string owner = inputArgs[2];
                output = animalCentre.Adopt(name, owner);
                break;

            case "History":
                name   = inputArgs[1];
                output = animalCentre.History(name);
                break;
            }

            return(output);
        }
        public void Run()
        {
            var animalCentre = new AnimalCentre();

            var input = Console.ReadLine();

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

                try
                {
                    if (commandType == "RegisterAnimal")
                    {
                        var type          = commands[1];
                        var name          = commands[2];
                        var energy        = int.Parse(commands[3]);
                        var happiness     = int.Parse(commands[4]);
                        var procedureTime = int.Parse(commands[5]);

                        Console.WriteLine(animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime));
                    }
                    else if (commandType == "Chip")
                    {
                        var name          = commands[1];
                        var procedureTime = int.Parse(commands[2]);

                        Console.WriteLine(animalCentre.Chip(name, procedureTime));
                    }
                    else if (commandType == "Vaccinate")
                    {
                        var name          = commands[1];
                        var procedureTime = int.Parse(commands[2]);

                        Console.WriteLine(animalCentre.Vaccinate(name, procedureTime));
                    }
                    else if (commandType == "Fitness")
                    {
                        var name          = commands[1];
                        var procedureTime = int.Parse(commands[2]);

                        Console.WriteLine(animalCentre.Fitness(name, procedureTime));
                    }
                    else if (commandType == "Play")
                    {
                        var name          = commands[1];
                        var procedureTime = int.Parse(commands[2]);

                        Console.WriteLine(animalCentre.Play(name, procedureTime));
                    }
                    else if (commandType == "DentalCare")
                    {
                        var name          = commands[1];
                        var procedureTime = int.Parse(commands[2]);

                        Console.WriteLine(animalCentre.DentalCare(name, procedureTime));
                    }
                    else if (commandType == "NailTrim")
                    {
                        var name          = commands[1];
                        var procedureTime = int.Parse(commands[2]);

                        Console.WriteLine(animalCentre.NailTrim(name, procedureTime));
                    }
                    else if (commandType == "Adopt")
                    {
                        var name  = commands[1];
                        var owner = commands[2];

                        Console.WriteLine(animalCentre.Adopt(name, owner));
                    }
                    else if (commandType == "History")
                    {
                        var procedureType = commands[1];

                        Console.WriteLine(animalCentre.History(procedureType));
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine($"{ex.GetType().Name}: {ex.Message}");
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine($"{ex.GetType().Name}: {ex.Message}");
                }
                input = Console.ReadLine();
            }

            var ownersAndPets = animalCentre.GetOwnersAndPets();

            OwnerFinishLines(ownersAndPets);
        }
Пример #26
0
        public void Run()
        {
            string command = Console.ReadLine();

            while (command != "End")
            {
                string[] args = command.Split();
                string   type = args[0];

                string[] arr = args.Skip(1).ToArray();

                try
                {
                    switch (type)
                    {
                    case "RegisterAnimal":
                        Console.WriteLine(centre.RegisterAnimal(arr[0], arr[1], int.Parse(arr[2]), int.Parse(arr[3]), int.Parse(arr[4])));
                        break;

                    case "Chip":
                        Console.WriteLine(centre.Chip(arr[0], int.Parse(arr[1])));
                        break;

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

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

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

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

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

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

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

                command = Console.ReadLine();
            }
            Console.WriteLine(centre.ToString());
        }
Пример #27
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (input != "End")
            {
                string[] currentInput = input.Split();
                string   type;

                try
                {
                    //•	RegisterAnimal {type} {name} {energy} {happiness} {procedureTime}
                    if (currentInput[0] == "RegisterAnimal")
                    {
                        type = currentInput[1];
                        string name          = currentInput[2];
                        int    energy        = int.Parse(currentInput[3]);
                        int    happiness     = int.Parse(currentInput[4]);
                        int    procedureTime = int.Parse(currentInput[5]);
                        string result        = animalCenter.RegisterAnimal(type, name, energy, happiness, procedureTime);
                        Console.WriteLine(result);
                    }
                    //•	Chip {name} {procedureTime}
                    if (currentInput[0] == "Chip")
                    {
                        string name          = currentInput[1];
                        int    procedureTime = int.Parse(currentInput[2]);
                        string result        = animalCenter.Chip(name, procedureTime);
                        Console.WriteLine(result);
                    }
                    //•	Vaccinate {name} {procedureTime}
                    if (currentInput[0] == "Vaccinate")
                    {
                        string name          = currentInput[1];
                        int    procedureTime = int.Parse(currentInput[2]);
                        string result        = animalCenter.Vaccinate(name, procedureTime);
                        Console.WriteLine(result);
                    }
                    //•	Fitness {name} {procedureTime}
                    if (currentInput[0] == "Fitness")
                    {
                        string name          = currentInput[1];
                        int    procedureTime = int.Parse(currentInput[2]);
                        string result        = animalCenter.Fitness(name, procedureTime);
                        Console.WriteLine(result);
                    }
                    //•	Play {name} {procedureTime}
                    if (currentInput[0] == "Play")
                    {
                        string name          = currentInput[1];
                        int    procedureTime = int.Parse(currentInput[2]);
                        string result        = animalCenter.Play(name, procedureTime);
                        Console.WriteLine(result);
                    }
                    //•	DentalCare {name} {procedureTime}
                    if (currentInput[0] == "DentalCare")
                    {
                        string name          = currentInput[1];
                        int    procedureTime = int.Parse(currentInput[2]);
                        string result        = animalCenter.DentalCare(name, procedureTime);
                        Console.WriteLine(result);
                    }
                    //•	NailTrim {name} {procedureTime}
                    if (currentInput[0] == "NailTrim")
                    {
                        string name          = currentInput[1];
                        int    procedureTime = int.Parse(currentInput[2]);
                        string result        = animalCenter.NailTrim(name, procedureTime);
                        Console.WriteLine(result);
                    }
                    //•	Adopt {animal name} {owner}
                    if (currentInput[0] == "Adopt")
                    {
                        string name   = currentInput[1];
                        string owner  = currentInput[2];
                        string result = animalCenter.Adopt(name, owner);
                        Console.WriteLine(result);
                    }
                    //•	History {procedureType}
                    if (currentInput[0] == "History")
                    {
                        string procedureType = currentInput[1];
                        string result        = animalCenter.History(procedureType);
                        Console.WriteLine(result);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("InvalidOperationException: " + ex.Message);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("ArgumentException: " + ex.Message);
                }

                input = Console.ReadLine();
            }

            Console.WriteLine(animalCenter.GetSummary());
        }
Пример #28
0
        public void Run()
        {
            string input  = reader.ReadLine();
            string result = string.Empty;

            while (input != "End")
            {
                string[] arguments = input.Split();

                string command = arguments[0];
                try
                {
                    switch (command)
                    {
                    case "RegisterAnimal":
                        string type          = arguments[1];
                        string name          = arguments[2];
                        int    energy        = int.Parse(arguments[3]);
                        int    happiness     = int.Parse(arguments[4]);
                        int    procedureTime = int.Parse(arguments[5]);

                        result = animalCentre.RegisterAnimal(type, name, energy, happiness, procedureTime);
                        break;

                    case "Chip":
                        string animalName        = arguments[1];
                        int    chipProcedureTime = int.Parse(arguments[2]);

                        result = animalCentre.Chip(animalName, chipProcedureTime);
                        break;

                    case "Vaccinate":
                        string vaccinateAnimalName    = arguments[1];
                        int    vaccinateProcedureTime = int.Parse(arguments[2]);

                        result = animalCentre.Vaccinate(vaccinateAnimalName, vaccinateProcedureTime);
                        break;

                    case "Fitness":
                        string fitnessAnimalName    = arguments[1];
                        int    fitnessProcedureTime = int.Parse(arguments[2]);

                        result = animalCentre.Fitness(fitnessAnimalName, fitnessProcedureTime);
                        break;

                    case "Play":
                        string platAnimalName    = arguments[1];
                        int    playProcedureTime = int.Parse(arguments[2]);

                        result = animalCentre.Play(platAnimalName, playProcedureTime);
                        break;

                    case "DentalCare":
                        string dentalAnimalName    = arguments[1];
                        int    dentalProcedureTime = int.Parse(arguments[2]);

                        result = animalCentre.DentalCare(dentalAnimalName, dentalProcedureTime);
                        break;

                    case "NailTrim":
                        string nailAnimalName    = arguments[1];
                        int    nailProcedureTime = int.Parse(arguments[2]);

                        result = animalCentre.NailTrim(nailAnimalName, nailProcedureTime);
                        break;

                    case "Adopt":
                        string animalToAdopt = arguments[1];
                        string ownerName     = arguments[2];

                        result = animalCentre.Adopt(animalToAdopt, ownerName);
                        break;

                    case "History":
                        string procedureType = arguments[1];

                        result = animalCentre.History(procedureType);
                        break;

                    default:
                        break;
                    }
                }
                catch (InvalidOperationException ae)
                {
                    result = "InvalidOperationException: " + ae.Message;
                }
                catch (ArgumentException ae)
                {
                    result = "ArgumentException: " + ae.Message;
                }

                writer.WriteLine(result);

                input = reader.ReadLine();
            }
            StringBuilder sb = new StringBuilder();

            foreach (var owner in animalCentre.AdoptedAnimals.OrderBy(x => x.Key))
            {
                sb.AppendLine($"--Owner: {owner.Key}");
                sb.Append("    - Adopted animals: ");

                foreach (var animal in owner.Value)
                {
                    sb.Append(animal.Name + " ");
                }
                sb.AppendLine();
            }

            result = sb.ToString().TrimEnd();
            writer.WriteLine(result);
        }