public void ReleasePet(string[] parameters) { string clinicName = parameters[0]; Clinic clinic = clinics.FirstOrDefault(c => c.Name == clinicName); Console.WriteLine(clinic.Release()); }
static void Main(string[] args) { int numberOfLines = int.Parse(Console.ReadLine()); List <Pet> pets = new List <Pet>(); List <Clinic> clinics = new List <Clinic>(); for (int i = 0; i < numberOfLines; i++) { List <string> commandArgs = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList(); string command = commandArgs[0]; switch (command) { case "Create": Create(commandArgs, pets, clinics); break; case "Add": Clinic currentClinic = clinics.FirstOrDefault(c => c.Name == commandArgs[2]); Pet currentPet = pets.FirstOrDefault(c => c.Name == commandArgs[1]); Console.WriteLine(currentClinic.Add(currentPet)); break; case "Release": Clinic currentClinicRelease = clinics.FirstOrDefault(c => c.Name == commandArgs[1]); Console.WriteLine(currentClinicRelease.Release()); break; case "HasEmptyRooms": Clinic currentClinicHasRoom = clinics.FirstOrDefault(c => c.Name == commandArgs[1]); Console.WriteLine(currentClinicHasRoom.HasEmptyRooms()); break; case "Print": PrintClinicRooms(clinics, commandArgs); break; } } }
public bool ReleasePet(string clinicName) { Clinic clinic = GetClinic(clinicName); return(clinic.Release()); }
private string ExecuteCommand(string command, string[] tokens) { string result = string.Empty; switch (command) { case "Create": string secondArg = tokens[0]; if (secondArg == "Pet") { CreatePet(tokens.Skip(1).ToArray()); } else { result = CreateClinic(tokens.Skip(1).ToArray()); } break; case "Add": string petName = tokens[0]; string clinicName = tokens[1]; result = "Invalid Operation!"; Pet pet = this.pets.FirstOrDefault(p => p.Name == petName); if (pet != null) { Clinic clinic = this.clinics.FirstOrDefault(c => c.Name == clinicName); if (clinic != null) { result = clinic.Add(pet).ToString(); } } break; case "Release": clinicName = tokens[0]; Clinic clinicToRelease = this.clinics.FirstOrDefault(c => c.Name == clinicName); if (clinicToRelease != null) { result = clinicToRelease.Release().ToString(); } break; case "HasEmptyRooms": clinicName = tokens[0]; result = this.clinics.FirstOrDefault(c => c.Name == clinicName)?.HasEmptyRooms.ToString(); break; case "Print": if (tokens.Length == 2) { clinicName = tokens[0]; int room = int.Parse(tokens[1]); result = this.clinics.FirstOrDefault(c => c.Name == clinicName)?.Print(room); } else { clinicName = tokens[0]; foreach (var p in this.clinics.FirstOrDefault(c => c.Name == clinicName)) { if (p == null) { result += "Room empty" + Environment.NewLine; } else { result += p + Environment.NewLine; } } } break; } return(result); }
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; } } }
public static void Main(string[] args) { Dictionary <string, Pet> pets = new Dictionary <string, Pet>(); Dictionary <string, Clinic> clinics = new Dictionary <string, Clinic>(); int lines = int.Parse(Console.ReadLine()); for (int i = 0; i < lines; i++) { string line = Console.ReadLine(); string[] parameters = line.Split(); switch (parameters[0]) { case "Create": if (parameters[1] == "Pet") { Pet pet = new Pet(parameters[2], int.Parse(parameters[3]), parameters[4]); pets[pet.Name] = pet; } else if (parameters[1] == "Clinic") { try { Clinic clinic = new Clinic(int.Parse(parameters[3])); clinics[parameters[2]] = clinic; } catch (Exception) { Console.WriteLine("Invalid Operation!"); } } break; case "Add": { Pet pet = pets[parameters[1]]; Clinic clinic = clinics[parameters[2]]; Console.WriteLine(clinic.Add(pet)); break; } case "Release": { Clinic clinic = clinics[parameters[1]]; Console.WriteLine(clinic.Release()); break; } case "HasEmptyRooms": { Clinic clinic = clinics[parameters[1]]; Console.WriteLine(clinic.HasEmptyRooms()); break; } case "Print": { Clinic clinic = clinics[parameters[1]]; if (parameters.Length == 2) { Console.WriteLine(clinic.Print()); } else if (parameters.Length == 3) { Console.WriteLine(clinic.Print(int.Parse(parameters[2]))); } break; } } } }
static void Main(string[] args) { var pets = new List <Pet>(); var clinics = new List <Clinic>(); int commandCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandCount; i++) { string[] commandInput = Console.ReadLine().Split(); string cmd = commandInput[0]; switch (cmd) { case "Create": string typeOfCreation = commandInput[1]; if (typeOfCreation == "Pet") { int age = int.Parse(commandInput[3]); Pet pett = new Pet(commandInput[2], age, commandInput[4]); pets.Add(pett); } else { try { int roomCount = int.Parse(commandInput[3]); var clinic = new Clinic(commandInput[2], roomCount); clinics.Add(clinic); } catch (ArgumentException e) { Console.WriteLine(e.Message); } } break; case "Add": Pet pet = pets.FirstOrDefault(p => p.Name == commandInput[1]); Clinic clinicToAdd = clinics.FirstOrDefault(c => c.Name == commandInput[2]); Console.WriteLine(clinicToAdd.Add(pet)); break; case "Release": Clinic clinicToRelease = clinics.FirstOrDefault(c => c.Name == commandInput[1]); Console.WriteLine(clinicToRelease.Release()); break; case "HasEmptyRooms": Clinic clinicToCheck = clinics.FirstOrDefault(c => c.Name == commandInput[1]); Console.WriteLine(clinicToCheck.HasEmptyRooms); break; case "Print": Clinic 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; default: break; } } }
public void Run() { int numberOfCommands = int.Parse(Console.ReadLine()); string[] inputArgs; for (int curr = 0; curr < numberOfCommands; curr++) { inputArgs = Console.ReadLine().Split(); string command = inputArgs[0]; switch (command) { case "Create": string type = inputArgs[1]; string[] createArgs = inputArgs.Skip(2).ToArray(); if (type == "Pet") { Pet pet = PetFactory.CreatePet(createArgs); pets.Add(pet); } else if (type == "Clinic") { try { Clinic clinic = ClinicFactory.CreateClinic(createArgs); clinics.Add(clinic); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } break; case "Add": string addPetName = inputArgs[1]; string addClinicName = inputArgs[2]; Pet addPet = pets.First(p => p.Name == addPetName); Clinic addClinic = clinics.First(c => c.Name == addClinicName); Console.WriteLine(addClinic.Add(addPet)); break; case "Release": string releaseClinicName = inputArgs[1]; Clinic releaseClinic = clinics.First(c => c.Name == releaseClinicName); Console.WriteLine(releaseClinic.Release()); break; case "HasEmptyRooms": string hasEmptyRoomsClinicName = inputArgs[1]; Clinic hasEmptyRoomsClinic = clinics.First(c => c.Name == hasEmptyRoomsClinicName); Console.WriteLine(hasEmptyRoomsClinic.HasEmptyRooms()); break; case "Print": string printClinicName = inputArgs[1]; Clinic printClinic = clinics.First(c => c.Name == printClinicName); if (inputArgs.Length == 2) { printClinic.Print(); } else if (inputArgs.Length > 2) { int room = int.Parse(inputArgs[2]); printClinic.Print(room - 1); } break; } } }
public static void Main() { var pets = new List <Pet>(); var clinics = new List <Clinic>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] tokens = Console.ReadLine().Split(); string command = tokens[0]; switch (command) { case "Create": try { string typeOfCreation = tokens[1]; if (typeOfCreation == "Pet") { string name = tokens[2]; int age = int.Parse(tokens[3]); string kind = tokens[4]; Pet pet = new Pet(name, age, kind); pets.Add(pet); } else { string clinicName = tokens[2]; int roomCount = int.Parse(tokens[3]); Clinic clinic = new Clinic(clinicName, roomCount); clinics.Add(clinic); } } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } break; case "Add": string petName = tokens[1]; string clinicNameToAdd = tokens[2]; Pet petToAdd = pets.FirstOrDefault(p => p.Name == petName); Clinic clinicToAdd = clinics.FirstOrDefault(c => c.Name == clinicNameToAdd); Console.WriteLine(clinicToAdd.Add(petToAdd)); break; case "Release": string clinicToReleaseName = tokens[1]; Clinic clinicToRelease = clinics.FirstOrDefault(c => c.Name == clinicToReleaseName); Console.WriteLine(clinicToRelease.Release()); break; case "HasEmptyRooms": string clinicToCheckName = tokens[1]; Clinic clinicToCheck = clinics.FirstOrDefault(c => c.Name == clinicToCheckName); Console.WriteLine(clinicToCheck.HasEmptyRooms); break; case "Print": string clinicToPrintName = tokens[1]; Clinic clinicToPrint = clinics.FirstOrDefault(c => c.Name == clinicToPrintName); if (tokens.Length == 2) { Console.WriteLine(clinicToPrint.PrintAll()); } else { int roomNumberToPrint = int.Parse(tokens[2]); Console.WriteLine(clinicToPrint.Print(roomNumberToPrint)); } break; } } }
static void Main(string[] args) { List <Clinic> clinics = new List <Clinic>(); List <Pet> pets = new List <Pet>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] currentLine = Console.ReadLine().Split(); string currentCommand = currentLine[0]; try { switch (currentCommand) { case "Create": string itemToCreate = currentLine[1]; string name = currentLine[2]; if (itemToCreate.Equals("Pet")) { int age = int.Parse(currentLine[3]); string kind = currentLine[4]; Pet petToAdd = new Pet(name, age, kind); pets.Add(petToAdd); } else { int roomNumber = int.Parse(currentLine[3]); Clinic clinicToAdd = new Clinic(name, roomNumber); clinics.Add(clinicToAdd); } break; case "Add": string addPetName = currentLine[1]; string addClinicName = currentLine[2]; Pet accomodatePet = pets.FirstOrDefault(x => x.Name == addPetName); Clinic accomodateClinic = clinics.FirstOrDefault(x => x.Name == addClinicName); bool isAccomodateSuccess = accomodateClinic.Accomodate(accomodatePet); Console.WriteLine(isAccomodateSuccess); break; case "Release": string releaseAnimalClinic = currentLine[1]; Clinic releaseClinic = clinics.FirstOrDefault(x => x.Name == releaseAnimalClinic); bool isAnimalReleased = releaseClinic.Release(); Console.WriteLine(isAnimalReleased); break; case "HasEmptyRooms": string hasClinicEmptyRooms = currentLine[1]; Clinic freeRoomClinic = clinics.FirstOrDefault(x => x.Name == hasClinicEmptyRooms); bool hasEmptyRooms = freeRoomClinic.HasEmptyRooms(); Console.WriteLine(hasEmptyRooms); break; case "Print": string printClinicName = currentLine[1]; Clinic printClinic = clinics.FirstOrDefault(x => x.Name == printClinicName); if (currentLine.Length == 2) { printClinic.Print(); } else { int roomNumber = int.Parse(currentLine[2]); printClinic.Print(roomNumber); } break; default: break; } } catch (Exception e) { Console.WriteLine(e.Message); } } }