public static void Main()
    {
        int commandCount = int.Parse(Console.ReadLine());

        List <Pet>       pets    = new List <Pet>();
        List <PetClinic> clinics = new List <PetClinic>();

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

            switch (command)
            {
            case "Create":
                try
                {
                    string typeOfCreation = commandInput[1];
                    if (typeOfCreation == "Pet")
                    {
                        string name = commandInput[2];
                        int    age  = int.Parse(commandInput[3]);
                        string kind = commandInput[4];

                        Pet pet = new Pet(name, age, kind);
                        pets.Add(pet);
                    }
                    else
                    {
                        string    name      = commandInput[2];
                        int       roomCount = int.Parse(commandInput[3]);
                        PetClinic clinic    = new PetClinic(name, roomCount);
                        clinics.Add(clinic);
                    }
                }
                catch (InvalidOperationException invalidOperationException)
                {
                    Console.WriteLine(invalidOperationException.Message);
                }
                break;

            case "Add":
                Pet       petToAdd    = pets.FirstOrDefault(p => p.Name == commandInput[1]);
                PetClinic clinicToAdd = clinics.FirstOrDefault(c => c.Name == commandInput[2]);
                Console.WriteLine(clinicToAdd.Add(petToAdd));
                break;

            case "Release":
                PetClinic clinicToRelease = clinics.FirstOrDefault(c => c.Name == commandInput[1]);
                Console.WriteLine(clinicToRelease.Release());
                break;

            case "HasEmptyRooms":
                PetClinic clinicToCheck = clinics.FirstOrDefault(c => c.Name == commandInput[1]);
                Console.WriteLine(clinicToCheck.HasEmptyRooms);
                break;

            case "Print":
                PetClinic clinicToPrint = clinics.FirstOrDefault(c => c.Name == commandInput[1]);
                if (commandInput.Length == 3)
                {
                    int roomNumber = int.Parse(commandInput[2]);
                    Console.WriteLine(clinicToPrint.Print(roomNumber));
                }
                else
                {
                    Console.WriteLine(clinicToPrint.PrintAll());
                }
                break;
            }
        }
    }
Esempio n. 2
0
    static void Main(string[] args)
    {
        List <Pet>       pets       = new List <Pet>();
        List <PetClinic> petClinics = new List <PetClinic>();
        int numberOfCommands        = int.Parse(Console.ReadLine());

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

            switch (command)
            {
            case "Create":
                try
                {
                    string typeOfCreation = input[1];
                    if (typeOfCreation == "Pet")
                    {
                        int age = int.Parse(input[3]);
                        Pet pet = new Pet(input[2], age, input[4]);
                        pets.Add(pet);
                    }
                    else if (typeOfCreation == "Clinic")
                    {
                        int       roomCount = int.Parse(input[3]);
                        PetClinic petClinic = new PetClinic(input[2], roomCount);
                        petClinics.Add(petClinic);
                    }
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message);
                }
                break;

            case "Add":
                Pet       petToAdd = pets.FirstOrDefault(p => p.Name == input[1]);
                PetClinic clinic   = petClinics.FirstOrDefault(p => p.Name == input[2]);
                Console.WriteLine(clinic.Add(petToAdd));
                break;

            case "Release":
                PetClinic clinicToRelease = petClinics.FirstOrDefault(p => p.Name == input[1]);
                Console.WriteLine(clinicToRelease.Release());
                break;

            case "HasEmptyRooms":
                PetClinic clinicEmpty = petClinics.FirstOrDefault(p => p.Name == input[1]);
                Console.WriteLine(clinicEmpty.HasEmptyRooms);
                break;

            case "Print":
                PetClinic clinicToPrint = petClinics.FirstOrDefault(p => p.Name == input[1]);
                if (input.Length == 3)
                {
                    int roomNumber = int.Parse(input[2]);
                    Console.WriteLine(clinicToPrint.Print(roomNumber));
                }
                else
                {
                    Console.WriteLine(clinicToPrint.Print());
                }
                break;
            }
        }
    }