public bool AddPet(string petName, string clinicName) { Pet pet = this.petByName[petName]; PetClinic petClinic = this.GetClinicByName(clinicName); return(petClinic.AddPet(pet)); }
private void Create(string[] input) { var type = input[1]; if (type == "Clinic") { var petClinic = new PetClinic(input[2], int.Parse(input[3])); clinics.Add(petClinic); } else { var pet = new Pet(input[2], int.Parse(input[3]), input[4]); pets.Add(pet); } }
static void Main(string[] args) { List <Pet> pets = new List <Pet>(); List <PetClinic> petClinics = new List <PetClinic>(); int commandCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandCount; i++) { string[] commandInput = Console.ReadLine().Split(); string command = commandInput[0]; switch (command) { case "Create": string typeOFCreation = commandInput[1]; if (typeOFCreation == "Pet") { int age = int.Parse(commandInput[3]); Pet pet = new Pet(commandInput[2], age, commandInput[4]); pets.Add(pet); } else { int roomCount = int.Parse(commandInput[3]); PetClinic clinic = new PetClinic(commandInput[2], roomCount); petClinics.Add(clinic); } break; case "Add": Pet petAdd = pets.FirstOrDefault(p => p.Name == commandInput[1]); break; } } }
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; } } }
public void Run() { var commandCount = int.Parse(Console.ReadLine()); var pets = new List <Pet>(); var clinics = new List <PetClinic>(); for (int i = 0; i < commandCount; i++) { var input = Console.ReadLine().Split(); var command = input[0]; var commandArgs = input.Skip(1).ToArray(); switch (command) { case "Create": try { if (commandArgs[0] == "Pet") { var name = commandArgs[1]; var age = int.Parse(commandArgs[2]); var kind = commandArgs[3]; var pet = new Pet(name, age, kind); pets.Add(pet); } else { var roomCount = int.Parse(commandArgs[2]); var clinicName = commandArgs[1]; var clinic = new PetClinic(clinicName, roomCount); clinics.Add(clinic); } } catch (Exception e) { result.AppendLine(e.Message); } break; case "Add": var petName = commandArgs[0]; var petToAdd = pets.FirstOrDefault(p => p.Name == petName); var clinicToAdd = clinics.FirstOrDefault(c => c.Name == commandArgs[1]); result.AppendLine(clinicToAdd.Add(petToAdd).ToString()); break; case "Release": var clinicToRelease = clinics.FirstOrDefault(c => c.Name == commandArgs[0]); result.AppendLine(clinicToRelease.Release().ToString()); break; case "HasEmptyRooms": var clinicTocheck = clinics.FirstOrDefault(c => c.Name == commandArgs[0]); result.AppendLine(clinicTocheck.HasEmptyRooms.ToString()); break; case "Print": var clinicToPrint = clinics.FirstOrDefault(c => c.Name == commandArgs[0]); if (commandArgs.Length == 2) { var roomNumber = int.Parse(commandArgs[1]); result.AppendLine(clinicToPrint.Print(roomNumber)); } else { result.AppendLine(clinicToPrint.Print()); } break; } } Console.WriteLine(this.result.ToString().TrimEnd()); }
public string Print(string clinicName, int room) { PetClinic petClinic = this.GetClinicByName(clinicName); return(petClinic.Print(room)); }
public bool HasEmptyRoom(string clinicName) { PetClinic petClinic = this.GetClinicByName(clinicName); return(petClinic.HasEmptyRooms); }
public bool Release(string clinicName) { PetClinic petClinic = this.GetClinicByName(clinicName); return(petClinic.ReleasePet()); }
public void CreateClinic(string name, int rooms) { PetClinic petClinic = new PetClinic(name, rooms); this.petClinicByName[name] = petClinic; }
private PetClinic GetClinicByName(string clinicName) { PetClinic petClinic = this.petClinicByName[clinicName]; return(petClinic); }
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; } } }
public void ExecuteCommand(string command, List <PetClinic> clinics, List <Pet> pets) { string[] commandData = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string commandType = commandData[0]; string petName = string.Empty; string clinicName = string.Empty; PetClinic currentClinic = null; try { switch (commandType) { case "Create": if (commandData[1] == "Clinic") { clinicName = commandData[2]; int numberOfRooms = int.Parse(commandData[3]); clinics.Add(new PetClinic(clinicName, numberOfRooms)); } else if (commandData[1] == "Pet") { petName = commandData[2]; int age = int.Parse(commandData[3]); string kind = commandData[4]; pets.Add(new Pet(petName, age, kind)); } break; case "Add": petName = commandData[1]; clinicName = commandData[2]; currentClinic = clinics.FirstOrDefault(c => c.Name == clinicName); var currentPet = pets.FirstOrDefault(p => p.Name == petName); Console.WriteLine(currentClinic.AddPet(currentPet)); break; case "Release": clinicName = commandData[1]; currentClinic = clinics.FirstOrDefault(c => c.Name == clinicName); Console.WriteLine(currentClinic.Release()); break; case "Print": clinicName = commandData[1]; currentClinic = clinics.FirstOrDefault(c => c.Name == clinicName); if (commandData.Length < 3) { Console.Write(currentClinic.PrintAll()); } else { int roomIndex = int.Parse(commandData[2]); Console.WriteLine(currentClinic.PrintRoom(roomIndex)); } break; case "HasEmptyRooms": clinicName = commandData[1]; currentClinic = clinics.FirstOrDefault(c => c.Name == clinicName); Console.WriteLine(currentClinic.HasEmptyRooms); break; } } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } catch (Exception) { Console.WriteLine("Invalid Operation!"); } }