Exemplo n.º 1
0
    private void CommandDispatcher()
    {
        int count = int.Parse(Console.ReadLine());

        while (count > 0)
        {
            string[] args = Console.ReadLine().Split();

            string command = args[0];

            if (command == "Create")
            {
                command = command + " " + args[1];
            }

            try
            {
                switch (command)
                {
                case "Create Pet":
                    manager.CreatePet(args);
                    break;

                case "Create Clinic":
                    manager.CreateClinic(args);
                    break;

                case "Add":
                    writer.WriteLine(manager.AddPet(args).ToString());
                    break;

                case "Release":
                    writer.WriteLine(manager.Release(args).ToString());
                    break;

                case "HasEmptyRooms":
                    writer.WriteLine(manager.HasEmptyRooms(args).ToString());
                    break;

                case "Print":
                    writer.WriteLine(manager.Print(args));
                    break;

                default:
                    throw new ArgumentException("Wrong command!");
                }
            }
            catch (ArgumentException ae)
            {
                writer.WriteLine(ae.Message);
            }
            catch (InvalidOperationException ioe)
            {
                writer.WriteLine(ioe.Message);
            }

            count--;
        }
    }
Exemplo n.º 2
0
    public void Run()
    {
        int n = int.Parse(Console.ReadLine());

        for (int counter = 0; counter < n; counter++)
        {
            List <string> args = Console.ReadLine()
                                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                 .ToList();

            string command = args[0];
            args.RemoveAt(0);

            switch (command)
            {
            case "Create":
                string param = args[0];
                args.RemoveAt(0);

                if (param == "Pet")
                {
                    manager.CreatePet(args);
                }
                else
                {
                    try
                    {
                        manager.CreateClinic(args);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                break;

            case "Add":
                Console.WriteLine(manager.Add(args)); break;

            case "Release":
                Console.WriteLine(manager.Release(args[0])); break;

            case "HasEmptyRooms":
                Console.WriteLine(manager.HasEmptyRooms(args[0])); break;

            case "Print":
                if (args.Count > 1)
                {
                    manager.Print(args[0], int.Parse(args[1]));
                }
                else
                {
                    manager.Print(args[0]);
                }
                break;
            }
        }
    }
Exemplo n.º 3
0
    public void Start()
    {
        var numberOfCommands = int.Parse(Console.ReadLine());

        while (numberOfCommands > 0)
        {
            var commandArgs = Console.ReadLine().Split();
            var command     = commandArgs[0];
            commandArgs = commandArgs.Skip(1).ToArray();
            string result;
            try
            {
                switch (command)
                {
                case "Create":
                    var type = commandArgs[0];
                    commandArgs = commandArgs.Skip(1).ToArray();
                    if (type == "Pet")
                    {
                        clinicManager.CreatePet(commandArgs);
                    }
                    else
                    {
                        clinicManager.CreateClinic(commandArgs);
                    }

                    break;

                case "Add":
                    result = this.clinicManager.Add(commandArgs).ToString();
                    this.resultString.AppendLine(result);
                    break;

                case "Release":
                    result = clinicManager.Release(commandArgs).ToString();
                    this.resultString.AppendLine(result);
                    break;

                case "HasEmptyRooms":
                    result = clinicManager.HasEmptyRooms(commandArgs[0]).ToString();
                    this.resultString.AppendLine(result);
                    break;

                case "Print":
                    var clinicName = commandArgs[0];

                    if (commandArgs.Length > 1)
                    {
                        var roomNumber = int.Parse(commandArgs[1]);
                        result = this.clinicManager.Print(clinicName, roomNumber);
                        this.resultString.AppendLine(result);
                    }
                    else
                    {
                        result = this.clinicManager.Print(clinicName);
                        this.resultString.Append(result);
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                this.resultString.AppendLine(e.Message);
            }

            numberOfCommands--;
        }

        Console.WriteLine(this.resultString.ToString().Trim());
    }