private static void ExecuteHasEmptyRoomsCommand(string[] args) { string clinicName = args[0]; Clinic targetClinic = clinicsByName[clinicName]; Console.WriteLine(targetClinic.HasEmptyRooms()); }
public bool HasEmptyRooms(string[] args) { string clinicName = args[1]; Clinic clinic = FindClinic(clinicName); return(clinic.HasEmptyRooms()); }
/* * creating a pet, creating a clinic, adding a pet to a clinic, * releasing a pet from a clinic, printing information about a specific * room in a clinic or printing information about all rooms in a clinic. */ public void Interpret() { List <string> cmdArgs = Console.ReadLine() .Split(' ') .ToList(); string command = cmdArgs[0]; cmdArgs.RemoveAt(0); switch (command) { case "Create": if (cmdArgs[0] == "Pet") { cmdArgs.RemoveAt(0); Pet.CreatePet(cmdArgs); } else if (cmdArgs[0] == "Clinic") { cmdArgs.RemoveAt(0); Clinic.CreateClinic(cmdArgs); } break; case "Add": string addResult = Clinic.AddPetToClinic(cmdArgs[0], cmdArgs[1]).ToString(); Console.WriteLine(addResult.ToLower()); break; case "Release": string result = Clinic.ReleasePetFromClinic(cmdArgs[0]).ToString(); Console.WriteLine(result.ToLower()); break; case "HasEmptyRooms": string resultFrom = Clinic.HasEmptyRooms(cmdArgs[0]).ToString(); Console.WriteLine(resultFrom.ToLower()); break; case "Print": if (cmdArgs.Count == 1) { Clinic.PrintEveryRoomInClinic(cmdArgs[0]); } else { Clinic.PrintClinicRoom(cmdArgs[0], int.Parse(cmdArgs[1])); } break; default: Console.WriteLine("No such a command!"); return; } }
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; } } }
private static void CheckForEmptyRooms(string clinicName) { Clinic currentClinic = allClinics[clinicName]; Console.WriteLine(currentClinic.HasEmptyRooms()); }
public bool DoesHaveEmptyRooms(string clinicName) { Clinic clinic = GetClinic(clinicName); return(clinic.HasEmptyRooms()); }
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; } } } }
private static bool CheckForEmptyRooms(string clinicName) { Clinic currentClinic = allClinics[clinicName]; return(currentClinic.HasEmptyRooms()); }
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() { int numberOfCommands = int.Parse(Console.ReadLine()); List <Pet> pets = new List <Pet>(); List <Clinic> clinics = new List <Clinic>(); for (int i = 0; i < numberOfCommands; i++) { string[] command = Console.ReadLine().Split(); switch (command[0]) { case "Create": if (command[1] == "Pet") { Pet pet = new Pet(command[2], int.Parse(command[3]), command[4]); pets.Add(pet); } else if (command[1] == "Clinic") { int numberOfRooms = int.Parse(command[3]); if (numberOfRooms % 2 == 0) { Console.WriteLine("Invalid Operation!"); } else { Clinic clinic = new Clinic(command[2], numberOfRooms); clinics.Add(clinic); } } break; case "Add": if (!pets.Any(p => p.Name == command[1]) || !clinics.Any(c => c.Name == command[2])) { Console.WriteLine("Invalid Operation!"); } else { Pet pet = pets.First(p => p.Name == command[1]); Clinic clinic = clinics.First(c => c.Name == command[2]); Console.WriteLine(clinic.AddPet(pet)); } break; case "Release": if (!clinics.Any(c => c.Name == command[1])) { Console.WriteLine("Invalid Operation!"); } else { Clinic clinic = clinics.First(c => c.Name == command[1]); Console.WriteLine(clinic.RemovePet()); } break; case "HasEmptyRooms": if (!clinics.Any(c => c.Name == command[1])) { Console.WriteLine("Invalid Operation!"); } else { Clinic clinic = clinics.First(c => c.Name == command[1]); Console.WriteLine(clinic.HasEmptyRooms()); } break; case "Print": if (!clinics.Any(c => c.Name == command[1])) { Console.WriteLine("Invalid Operation!"); } else { if (command.Length == 2) { Clinic clinic = clinics.First(c => c.Name == command[1]); Console.Write(clinic.ToString()); } else if (command.Length == 3) { Clinic clinic = clinics.First(c => c.Name == command[1]); Console.Write(clinic.PrintRoom(int.Parse(command[2]))); } } break; default: 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; } } }