public bool AddPet(string petName, string clinicName)
        {
            Pet    pet    = this.GetPet(petName);
            Clinic clinic = GetClinic(clinicName);
            bool   result = clinic.AddPet(pet);

            return(result);
        }
Exemplo n.º 2
0
    private static void ExecuteAddCommand(string[] args)
    {
        string petName    = args[0];
        string clinicName = args[1];

        Pet    targetPet    = petsByName[petName];
        Clinic targetClinic = clinicsByName[clinicName];

        Console.WriteLine(targetClinic.AddPet(targetPet));
    }
Exemplo n.º 3
0
    public bool Add(List <string> args)
    {
        string petName    = args[0];
        string clinicName = args[1];

        Pet pet = this.pets.FirstOrDefault(p => p.Name.CompareTo(petName) == 0);

        Clinic clinic = this.clinics[clinicName];

        if (this.HasEmptyRooms(clinicName))
        {
            return(clinic.AddPet(pet));
        }
        return(false);
    }
Exemplo n.º 4
0
        public void Run()
        {
            var numberOfCommands = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfCommands; i++)
            {
                var input = Console.ReadLine().Split();

                var    command = input[0];
                var    name    = string.Empty;
                Clinic clinic  = null;
                Pet    pet     = null;


                switch (command)
                {
                case "Create":
                    if (input.Length > 4)
                    {
                        pet = CreatePet(input);
                        this.pets.Add(pet);
                    }
                    else
                    {
                        clinic = CreateClinic(input);
                        this.clinics.Add(clinic);
                    }
                    break;

                case "Add":
                    var petToAdd = this.pets.
                                   First(p => p.Name == input[1]);

                    clinic = this.clinics.
                             First(c => c.Name == input[2]);

                    Console.WriteLine(clinic.AddPet(petToAdd));
                    break;

                case "Release":
                    clinic = this.clinics.
                             First(c => c.Name == input[1]);

                    Console.WriteLine(clinic.Release());
                    break;

                case "HasEmptyRooms":
                    clinic = this.clinics.
                             First(c => c.Name == input[1]);
                    Console.WriteLine(clinic.HasEmptyRooms());
                    break;

                case "Print":
                    clinic = this.clinics.
                             First(c => c.Name == input[1]);

                    if (input.Length > 2)
                    {
                        var roomID = int.Parse(input[2]);
                        clinic.PrintRoom(roomID);
                    }
                    else
                    {
                        clinic.PrintAllRooms();
                    }
                    break;
                }
            }
        }
Exemplo n.º 5
0
    private static void Run(string[] input)
    {
        string command = input[0];

        switch (command)
        {
        case "Create":
        {
            string typeOfCreation = input[1];
            if (typeOfCreation == "Pet")
            {
                Pet pet = new Pet(input[2], int.Parse(input[3]), input[4]);
                pets.Add(pet);
            }
            else
            {
                Clinic clinic = new Clinic(input[2], int.Parse(input[3]));

                clinics.Add(clinic);
            }
            break;
        }

        case "Add":
        {
            string petName    = input[1];
            string clinicName = input[2];

            Clinic clinic = clinics.FirstOrDefault(c => c.Name == clinicName);
            Pet    pet    = pets.FirstOrDefault(p => p.Name == petName);
            Console.WriteLine(clinic.AddPet(pet));
            break;
        }

        case "Release":
        {
            string clinicName = input[1];

            Clinic clinic = clinics.FirstOrDefault(c => c.Name == clinicName);
            Console.WriteLine(clinic.ReleasingPet());
            break;
        }

        case "HasEmptyRooms":
        {
            string clinicName = input[1];

            Clinic clinic = clinics.FirstOrDefault(c => c.Name == clinicName);
            Console.WriteLine(clinic.HasEmptyRoom());
            break;
        }

        case "Print":
        {
            string clinicName = input[1];
            Clinic clinic     = clinics.FirstOrDefault(c => c.Name == clinicName);
            if (input.Length == 2)
            {
                Console.WriteLine(clinic.ToString());
            }
            else
            {
                int roomNumber = int.Parse(input[2]);
                Console.WriteLine(clinic.PrintRoom(roomNumber));
            }
            break;
        }
        }
    }
        private void Dispatch()
        {
            int countCommands = int.Parse(Console.ReadLine());

            for (int i = 0; i < countCommands; i++)
            {
                string[] inParams = Console.ReadLine().Split();
                string   command  = inParams[0];
                inParams = inParams.Skip(1).ToArray();

                switch (command)
                {
                case "Create":
                    if (inParams[0] == "Pet")
                    {
                        try
                        {
                            Pet newPet = new Pet(inParams[1], int.Parse(inParams[2]), inParams[3]);
                            this.pets.Add(inParams[1], newPet);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    else if (inParams[0] == "Clinic")
                    {
                        try
                        {
                            Clinic newClinic = new Clinic(inParams[1], int.Parse(inParams[2]));
                            this.clinics.Add(inParams[1], newClinic);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    break;

                case "Add":
                    Pet    pet    = this.pets.FirstOrDefault(x => x.Key == inParams[0]).Value;
                    Clinic clinic = this.clinics.FirstOrDefault(x => x.Key == inParams[1]).Value;
                    bool   result = (pet != null) && (clinic != null);

                    if (result)
                    {
                        if (result = clinic.AddPet(pet))
                        {
                            this.pets.Remove(inParams[0]);
                        }
                    }
                    else
                    {
                        result = false;
                    }

                    Console.WriteLine(result);
                    break;

                case "Release":
                    Console.WriteLine(this.clinics[inParams[0]].Release());
                    break;

                case "HasEmptyRooms":
                    Console.WriteLine(this.clinics[inParams[0]].HasEmptyRooms());
                    break;

                case "Print":
                    if (inParams.Length == 1)
                    {
                        Console.WriteLine(this.clinics[inParams[0]].ToString());
                    }
                    else if (inParams.Length == 2)
                    {
                        Pet petForPrint = this.clinics[inParams[0]].Rooms[int.Parse(inParams[1]) - 1];
                        Console.WriteLine(petForPrint?.ToString() ?? "Room empty");
                    }
                    break;
                }
            }
        }
    public static void Main()
    {
        int           numberOfCommands = int.Parse(Console.ReadLine());
        List <Pet>    pets             = new List <Pet>();
        List <Clinic> clinics          = new List <Clinic>();

        for (int i = 0; i < numberOfCommands; i++)
        {
            string[] command = Console.ReadLine().Split();

            switch (command[0])
            {
            case "Create":
                if (command[1] == "Pet")
                {
                    Pet pet = new Pet(command[2], int.Parse(command[3]), command[4]);
                    pets.Add(pet);
                }
                else if (command[1] == "Clinic")
                {
                    int numberOfRooms = int.Parse(command[3]);

                    if (numberOfRooms % 2 == 0)
                    {
                        Console.WriteLine("Invalid Operation!");
                    }
                    else
                    {
                        Clinic clinic = new Clinic(command[2], numberOfRooms);
                        clinics.Add(clinic);
                    }
                }
                break;

            case "Add":
                if (!pets.Any(p => p.Name == command[1]) ||
                    !clinics.Any(c => c.Name == command[2]))
                {
                    Console.WriteLine("Invalid Operation!");
                }
                else
                {
                    Pet    pet    = pets.First(p => p.Name == command[1]);
                    Clinic clinic = clinics.First(c => c.Name == command[2]);
                    Console.WriteLine(clinic.AddPet(pet));
                }
                break;

            case "Release":
                if (!clinics.Any(c => c.Name == command[1]))
                {
                    Console.WriteLine("Invalid Operation!");
                }
                else
                {
                    Clinic clinic = clinics.First(c => c.Name == command[1]);
                    Console.WriteLine(clinic.RemovePet());
                }
                break;

            case "HasEmptyRooms":
                if (!clinics.Any(c => c.Name == command[1]))
                {
                    Console.WriteLine("Invalid Operation!");
                }
                else
                {
                    Clinic clinic = clinics.First(c => c.Name == command[1]);
                    Console.WriteLine(clinic.HasEmptyRooms());
                }
                break;

            case "Print":
                if (!clinics.Any(c => c.Name == command[1]))
                {
                    Console.WriteLine("Invalid Operation!");
                }
                else
                {
                    if (command.Length == 2)
                    {
                        Clinic clinic = clinics.First(c => c.Name == command[1]);
                        Console.Write(clinic.ToString());
                    }
                    else if (command.Length == 3)
                    {
                        Clinic clinic = clinics.First(c => c.Name == command[1]);
                        Console.Write(clinic.PrintRoom(int.Parse(command[2])));
                    }
                }
                break;

            default:
                break;
            }
        }
    }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            int numOfCommands = int.Parse(Console.ReadLine());

            for (int i = 0; i < numOfCommands; i++)
            {
                string[] cmdArgs       = Console.ReadLine().Split();
                string   command       = cmdArgs[0];
                Clinic   currentClinic = null;

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

                switch (command)
                {
                case "Create Pet":
                    Pet pet = new Pet(cmdArgs[2], int.Parse(cmdArgs[3]), cmdArgs[4]);
                    allPets.Add(pet);
                    break;

                case "Create Clinic":
                    try
                    {
                        Clinic clinic = new Clinic(cmdArgs[2], int.Parse(cmdArgs[3]));
                        allClinics.Add(clinic);
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;

                case "Add":
                    string petName    = cmdArgs[1];
                    string clinicName = cmdArgs[2];

                    try
                    {
                        Pet petToAdd = allPets.FirstOrDefault(p => p.Name == petName);
                        if (petToAdd == null)
                        {
                            throw new InvalidOperationException("Invalid Operation!");
                        }

                        currentClinic = GetClinic(clinicName);
                        Console.WriteLine(currentClinic.AddPet(petToAdd));
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;

                case "Release":
                    currentClinic = GetClinic(cmdArgs[1]);
                    Console.WriteLine(currentClinic.ReleasePet());
                    break;

                case "HasEmptyRooms":
                    currentClinic = GetClinic(cmdArgs[1]);
                    Console.WriteLine(currentClinic.HasEmptyRooms());
                    break;

                case "Print":
                    currentClinic = GetClinic(cmdArgs[1]);

                    if (cmdArgs.Length == 2)
                    {
                        currentClinic.PrintAll();
                    }
                    else
                    {
                        currentClinic.Print(int.Parse(cmdArgs[2]));
                    }
                    break;
                }
            }
        }