コード例 #1
0
        public Hotel CreateAHotel()
        {
            Console.Write("Enter hotel name: ");
            var name = Console.ReadLine();

            Console.Write("Enter hotel city: ");
            var city = Console.ReadLine();

            Console.Write($"Enter number of rooms for {name}: ");
            var nr = int.Parse(Console.ReadLine());

            Hotel hotel = new Hotel(name, city);

            for (int i = 0; i < nr; i++)
            {
                var roomNumber = i;

                Console.Write($"Adults for room {roomNumber}: ");
                var adults = int.Parse(Console.ReadLine());

                Console.Write($"Children for room {roomNumber}: ");
                var children = int.Parse(Console.ReadLine());

                Console.Write($"Amount for room {roomNumber}: ");
                var amount = int.Parse(Console.ReadLine());

                var room = new Room(roomNumber, adults, children, new Rate(amount, "USD"));
                hotel.AddRoom(room);
            }

            Console.WriteLine();

            return(hotel);
        }
コード例 #2
0
ファイル: HotelApp.cs プロジェクト: BurgheleaDaniel/.net
        static void Main(string[] args)
        {
            HotelManager hotelManager = new HotelManager();

            Hotel hotel1 = new Hotel()
            {
                Name = "Hotel no. 1", City = 10
            };
            Hotel hotel2 = new Hotel()
            {
                Name = "Hotel no. 2", City = 11
            };
            Hotel hotel3 = new Hotel()
            {
                Name = "Hotel no. 3", City = 12
            };

            Rate rate1 = new Rate()
            {
                Amount = 99.99m, Currency = 25
            };
            Rate rate2 = new Rate()
            {
                Amount = 59.99m, Currency = 25
            };
            Rate rate3 = new Rate()
            {
                Amount = 120.99m, Currency = 25
            };
            Rate rate4 = new Rate()
            {
                Amount = 499.99m, Currency = 25
            };

            Room room1 = new Room()
            {
                Name = "Room no. 1", Rate = rate1, Adults = 2, Children = 1
            };
            Room room2 = new Room()
            {
                Name = "Room no. 2", Rate = rate2, Adults = 4, Children = 0
            };
            Room room3 = new Room()
            {
                Name = "Room no. 3", Rate = rate3, Adults = 4, Children = 2
            };
            Room room4 = new Room()
            {
                Name = "Room no. 4", Rate = rate4, Adults = 2, Children = 2
            };

            hotel1.AddRoom(room1).AddRoom(room2).AddRoom(room3).AddRoom(room4);
            hotel2.AddRoom(room1).AddRoom(room2).AddRoom(room3).AddRoom(room4);
            hotel3.AddRoom(room1).AddRoom(room2).AddRoom(room3).AddRoom(room4);

            hotelManager.AddHotel(hotel1);
            hotelManager.AddHotel(hotel2);
            hotelManager.AddHotel(hotel3);

            int noOfRooms = 3;
            int noOfDays  = 5;

            foreach (Hotel hotel in hotelManager.GetAllHotels())
            {
                int index = 0;
                hotel.Print();
                foreach (Room item in hotel.GetAllRooms())
                {
                    item.Print();

                    decimal priceForNoOfRooms = hotel.GetPriceForNumberOfRooms(index++, noOfRooms);
                    decimal priceForNoOfDays  = item.GetPriceForDays(noOfDays);
                    Console.WriteLine($"Price for {noOfRooms} rooms: {priceForNoOfRooms}");
                    Console.WriteLine($"Price for {noOfDays} days: {priceForNoOfDays}");
                }
            }

            hotelManager.DeleteHotel(0);

            decimal maxAmount = 108;

            foreach (Hotel hotel in hotelManager.GetAllHotels())
            {
                int index = 0;
                hotel.Print();
                foreach (Room item in hotel.GetAllRooms(maxAmount))
                {
                    item.Print();

                    decimal priceForNoOfRooms = hotel.GetPriceForNumberOfRooms(index++, noOfRooms);
                    decimal priceForNoOfDays  = item.GetPriceForDays(noOfDays);
                    Console.WriteLine($"Price for {noOfRooms} rooms: {priceForNoOfRooms}");
                    Console.WriteLine($"Price for {noOfDays} days: {priceForNoOfDays}");
                }
            }
        }