public void Print(string[] parameters) { string clinicName = parameters[0]; Clinic clinic = clinics.FirstOrDefault(c => c.Name == clinicName); if (parameters.Length == 2) { int roomNumber = int.Parse(parameters[1]); Console.WriteLine(clinic.Print(roomNumber)); } else { Console.WriteLine(clinic.Print()); } }
private static void PrintClinicInfo(List <string> commandTokens) { Clinic currentClinic = allClinics[commandTokens[0]]; string result = null; if (commandTokens.Count == 1) { result = currentClinic.Print(); } else { int roomIndex = int.Parse(commandTokens[1]) - 1; result = currentClinic.Print(roomIndex); } Console.WriteLine(result); }
private static void Print(string[] args) { string clinicName = args[1]; // Print {clinic's name} if (args.Length == 2) { Clinic currentClinic = clinics.FirstOrDefault(c => c.Name.Equals(clinicName)); foreach (Pet pet in currentClinic) { if (pet != null) { Console.WriteLine(pet); } else { Console.WriteLine("Room empty"); } } } // Print {clinic's name} {room} else if (args.Length == 3) { int room = int.Parse(args[2]); Clinic currentClinic = clinics.FirstOrDefault(c => c.Name.Equals(clinicName)); Console.WriteLine(currentClinic.Print(room)); } }
private static string PrintClinicInfo(List <string> commandArgs) { Clinic currentClinic = allClinics[commandArgs[0]]; var result = string.Empty; if (commandArgs.Count == 1) { result = currentClinic.Print(); } else { var roomIndex = int.Parse(commandArgs[1]) - 1; result = currentClinic.Print(roomIndex); } return(result); }
private static void Print(string[] cmdArgs) { string clinicName = cmdArgs[1]; Clinic clinic = GetClinicByName(clinicName); string result = null; if (cmdArgs.Length == 2) { result = clinic.Print(); } else if (cmdArgs.Length == 3) { int roomIndex = int.Parse(cmdArgs[2]) - 1; result = clinic.Print(roomIndex); } Console.WriteLine(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; } } }
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); } } }
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; } } }