using
System;
using
System.Collections.Generic;
using
System.Linq;
public
class
Hotel
{
public
string
Name {
get
;
set
; }
public
int
RoomAvl {
get
;
set
; }
public
string
Location {
get
;
set
; }
public
int
Rating {
get
;
set
; }
public
int
PricePr {
get
;
set
; }
}
public
class
User : Hotel
{
public
string
Uname {
get
;
set
; }
public
int
UId {
get
;
set
; }
public
int
Cost {
get
;
set
; }
}
public
class
Program
{
static
int
SortByBan(Hotel A, Hotel B)
{
return
A.Name.CompareTo(B.Name);
}
static
int
SortByr(Hotel A, Hotel B)
{
return
B.Rating.CompareTo(A.Rating);
}
static
int
SortByRoomAvailable(Hotel A, Hotel B)
{
return
A.RoomAvl.CompareTo(B.RoomAvl);
}
static
void
PrintHotelData(List<Hotel> hotels)
{
Console.WriteLine(
"PRINT HOTELS DATA:"
);
Console.WriteLine(
"HotelName Room Available Location Rating PricePer Room:"
);
for
(
int
i = 0; i < 3; i++)
{
Console.WriteLine($
"{hotels[i].Name} {hotels[i].RoomAvl} {hotels[i].Location} {hotels[i].Rating} {hotels[i].PricePr}"
);
}
Console.WriteLine();
}
static
void
SortHotelByName(List<Hotel> hotels)
{
Console.WriteLine(
"SORT BY NAME:"
);
hotels.Sort(SortByBan);
foreach
(
var
hotel
in
hotels)
{
Console.WriteLine($
"{hotel.Name} {hotel.RoomAvl} {hotel.Location} {hotel.Rating} {hotel.PricePr}"
);
}
Console.WriteLine();
}
static
void
SortHotelByRating(List<Hotel> hotels)
{
Console.WriteLine(
"SORT BY A RATING:"
);
hotels.Sort(SortByr);
foreach
(
var
hotel
in
hotels)
{
Console.WriteLine($
"{hotel.Name} {hotel.RoomAvl} {hotel.Location} {hotel.Rating} {hotel.PricePr}"
);
}
Console.WriteLine();
}
static
void
PrintHotelBycity(
string
s, List<Hotel> hotels)
{
Console.WriteLine($
"HOTELS FOR {s} LOCATION IS:"
);
foreach
(
var
hotel
in
hotels)
{
if
(hotel.Location == s)
{
Console.WriteLine($
"{hotel.Name} {hotel.RoomAvl} {hotel.Location} {hotel.Rating} {hotel.PricePr}"
);
}
}
Console.WriteLine();
}
static
void
SortByRoomAvailable(List<Hotel> hotels)
{
Console.WriteLine(
"SORT BY ROOM AVAILABLE:"
);
hotels.Sort(SortByRoomAvailable);
for
(
int
i = hotels.Count - 1; i >= 0; i--)
{
Console.WriteLine($
"{hotels[i].Name} {hotels[i].RoomAvl} {hotels[i].Location} {hotels[i].Rating} {hotels[i].PricePr}"
);
}
Console.WriteLine();
}
static
void
PrintUserData(
string
[] userName,
int
[] userId,
int
[] bookingCost, List<Hotel> hotels)
{
List<User> user =
new
List<User>();
for
(
int
i = 0; i < 3; i++)
{
User u =
new
User
{
Uname = userName[i],
UId = userId[i],
Cost = bookingCost[i]
};
user.Add(u);
}
Console.WriteLine(
"PRINT USER BOOKING DATA:"
);
Console.WriteLine(
"UserName UserID HotelName BookingCost"
);
for
(
int
i = 0; i < user.Count; i++)
{
Console.WriteLine($
"{user[i].Uname} {user[i].UId} {hotels[i].Name} {user[i].Cost}"
);
}
}
static
void
HotelManagement(
string
[] userName,
int
[] userId,
string
[] hotelName,
int
[] bookingCost,
int
[] rooms,
string
[] locations,
int
[] ratings,
int
[] prices)
{
List<Hotel> hotels =
new
List<Hotel>();
for
(
int
i = 0; i < 3; i++)
{
Hotel h =
new
Hotel
{
Name = hotelName[i],
RoomAvl = rooms[i],
Location = locations[i],
Rating = ratings[i],
PricePr = prices[i]
};
hotels.Add(h);
}
Console.WriteLine();
PrintHotelData(hotels);
SortHotelByName(hotels);
SortHotelByRating(hotels);
PrintHotelBycity(
"Bangalore"
, hotels);
SortByRoomAvailable(hotels);
PrintUserData(userName, userId, bookingCost, hotels);
}
public
static
void
Main()
{
string
[] userName = {
"U1"
,
"U2"
,
"U3"
};
int
[] userId = { 2, 3, 4 };
string
[] hotelName = {
"H1"
,
"H2"
,
"H3"
};
int
[] bookingCost = { 1000, 1200, 1100 };
int
[] rooms = { 4, 5, 6 };
string
[] locations = {
"Bangalore"
,
"Bangalore"
,
"Mumbai"
};
int
[] ratings = { 5, 5, 3 };
int
[] prices = { 100, 200, 100 };
HotelManagement(userName, userId, hotelName, bookingCost, rooms, locations, ratings, prices);
}
}