Следует помнить, что сопоставление коллекций по индексу не очень хорошее. Намного лучше создать Class
с нужными вам полями. Вместо отдельных массивов для roomFits()
, roomCosts()
и т. Д. 1017 * у вас есть один класс, подобный этому:
Public Class Room
Public Property ID As Integer 'System/Database ID
Public Property RoomNumber As String
Public Property MaxOccupants As Integer
Public Property Price As Decimal
Public Property IsAvailable As Boolean
End Class
А затем список ONE для экземпляров этой комнаты класс:
Dim Rooms As New List(Of Room)()
Когда вы сможете загрузить данные для этого списка, мы можем начать смотреть на фактический метод:
Function SelectRoom(amountOfPeople As Integer, daysStaying As Integer) As Room
Dim matches = Rooms.Where(Func(r) r.MaxOccupants >= amountOfPeople AndAlso r.IsAvailable).ToList()
'Don't put the higher level program-flow here. Leave that for the calling method!
If matches.Count = 0 Then Return Nothing
Console.WriteLine("Rooms available:")
For Each r As Room in matches
Dim Price As Decimal = r.Price * daysStaying
Console.WriteLine($"{r.RoomNumber}")
Console.WriteLine($"Maximum in this room: {r.MaxOccupants}")
Console.WriteLine($"This room costs £{r.Price} per night")
Console.WriteLine($"Price for the visit: £{Price}")
Console.WriteLine()
Next r
Console.WriteLine("Which room would you like to pick? ")
Console.Write("> ")
Dim selectedRoomNumber As String = Console.ReadLine()
Return matches.FirstOrDefault(Function(r) r.RoomNumber = selectedRoomNumber)
End Function
Теперь мы должны изменить код вызова тоже.
Dim selectedRoom As Room = Nothing
Dim triesRemaining As Integer = 3
While selectedRoom Is Nothing AndAlso triesRemaining > 0
selectedRoom = SelectRoom(amountOfPeople, daysStaying)
If selectedRoom Is Nothing Then
triesRemaining -= 1
Console.Write("No rooms matched this criteria. Try again (Y/N)?" )
If Console.ReadLine().Trim().ToUpper() = "N" Then
triesRemaining = 0
End If
End If
End While