Exemplo n.º 1
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.º 2
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--;
        }
    }