public bool AddPet(string petName, string clinicName) { Clinic clinic = GetClinic(clinicName); Pet pet = GetPet(petName); return(clinic.Add(pet)); }
public void AddPet(string[] parameters) { string petName = parameters[0]; string clinicName = parameters[1]; Pet pet = pets.FirstOrDefault(p => p.Name == petName); Clinic clinic = clinics.FirstOrDefault(c => c.Name == clinicName); Console.WriteLine(clinic.Add(pet)); }
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 static void Main() { 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[] command = Console.ReadLine().Split().ToArray(); switch (command[0]) { case "Create": if (command[1] == "Pet") { Pet p = new Pet(command[2], int.Parse(command[3]), command[4]); pets.Add(p); } else if (command[1] == "Clinic") { try { Clinic c = new Clinic(command[2], int.Parse(command[3])); clinics.Add(c); } catch (ArgumentException e) { Console.WriteLine("Invalid Operation!"); } } break; case "Add": Pet pet = pets.FirstOrDefault(x => x.Name == command[1]); Clinic clinic = clinics.FirstOrDefault(x => x.Name == command[2]); Console.WriteLine(clinic?.Add(pet)); break; case "Release": Console.WriteLine(clinics.FirstOrDefault(x => x.Name == command[1])?.Release()); break; case "HasEmptyRooms": Console.WriteLine(clinics.FirstOrDefault(x => x.Name == command[1])?.HasEmptyRooms()); break; case "Print": if (command.Length == 3) { Console.WriteLine(clinics.FirstOrDefault(x => x.Name == command[1])?.PrintRoom(int.Parse(command[2]) - 1)); } else { Console.WriteLine(clinics.FirstOrDefault(x => x.Name == command[1])?.Print()); } break; } } }
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 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; } } }