using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
List<Destination> destinations = new()
{
new("UK", 0, new()
{
new("The Tower Hotel London", 1584),
new("Britannia International Hotel", 519),
new("The Midland", 1357),
}),
new("France", 120, new()
{
new("The People Paris Marais", 299),
new("Novotel Paris Centre Tour Eiffel", 1027),
new("Raddison Blu Hotel, Nice", 1104),
}),
new("Spain", 200, new()
{
new("The Hat Madrid", 183),
new("Hotel Nuevo Madrid", 562),
new("Doubletree by Hilton Hotel Girona", 455)
})
};
var britishCulture = new CultureInfo("en-GB");
CultureInfo.CurrentCulture= britishCulture;
CultureInfo.CurrentUICulture = britishCulture;
while (true)
{
Console.WriteLine("Welcome to the Ticket Booking System");
Console.WriteLine();
var destination = SelectDestination(destinations);
Console.WriteLine();
var hotel = SelectHotel(destination.Hotels);
Console.WriteLine();
var weeks = GetInteger($"How many weeks will you be staying at the {hotel.Name}? ");
var adults = GetInteger($"How many adults will be going to {destination.Name}? ");
var children = GetInteger($"How many children will be going to {destination.Name}? ");
var cost = destination.BaseCost + hotel.WeeklyRate * weeks * adults;
if (children >= 1)
cost = cost / 2;
Console.WriteLine();
Console.WriteLine($"The total price of your trip to {destination.Name} staying at the {hotel.Name} is {cost:C}.");
Console.WriteLine();
}
int GetInteger(string prompt, int max = Int32.MaxValue, int min = 0)
{
while (true)
{
Console.Write(prompt);
var input = Console.ReadLine();
if (int.TryParse(input, out int value))
{
if (min <= value && value <= max)
return value;
Console.WriteLine($"Please enter an integer in the range {min}-{max}.");
continue;
}
Console.WriteLine("Invalid integer.");
}
}
Destination SelectDestination(List<Destination> destinations)
{
Console.WriteLine("Please select one of the following destinations:");
for (int i = 0; i < destinations.Count; i++)
Console.WriteLine($"{i + 1}: {destinations[i].Name,-10} Base Cost: {destinations[i].BaseCost,8:C}");
int option = GetInteger("Where would you like to go? ", max: destinations.Count, min: 1); ;
return destinations[option - 1];
}
Hotel SelectHotel(List<Hotel> hotels)
{
Console.WriteLine("Please select one of the following hotels:");
for (int i = 0; i < hotels.Count; i++)
Console.WriteLine($"{i + 1}: {hotels[i].Name,-40} Weekly Rate: {hotels[i].WeeklyRate,10:C}");
int option = GetInteger("Where would you like to stay? ", max: hotels.Count, min: 1);
return hotels[option - 1];
}
record Hotel(string Name, decimal WeeklyRate);
record Destination(string Name, decimal BaseCost, List<Hotel> Hotels);