/// <summary> /// Prints guest list to the console /// </summary> /// <param name="hotel">List of Capsules</param> public static void ViewGuestList(List <Capsule> hotel) { if (hotel.Count == 0) { Console.WriteLine("No guests to view yet!"); ConsoleIO.AnyKeyToContinue(); return; } StringBuilder content = new StringBuilder(); int centerIndex = 0; //prompt user for capsule to center centerIndex = ReadInt($"Please enter the capsule you wish to view (1 - {hotel.Count})", 1, hotel.Count) - 1; //print header showing Capsule # Guest Name Console.WriteLine($"Capsule # : Guest Name"); //print 11 pairs (or as many on side as possible given the array scope) //add 5 to the left if there are... if (centerIndex - 5 >= 0) { for (int i = centerIndex - 5; i < centerIndex; i++) { AddToViewList(hotel, i, content); } } //add as many as possible to left if there aren't if (centerIndex - 5 < 0) { for (int i = 0; i < centerIndex; i++) { AddToViewList(hotel, i, content); } } //add center AddToViewList(hotel, centerIndex, content); //add 5 to the right if there are... if (hotel.Count - 5 - 1 >= centerIndex) { for (int i = centerIndex + 1; i < centerIndex + 6; i++) { AddToViewList(hotel, i, content); } } //add as many as possible to the right if there aren't if (hotel.Count - 5 - 1 < centerIndex) { for (int i = centerIndex + 1; i < hotel.Count; i++) { AddToViewList(hotel, i, content); } } //print result Console.WriteLine(content.ToString()); //pause until move on AnyKeyToContinue(); }