/// <summary>
 /// calculates and returns the rents for different hotels
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="type">The type.</param>
 /// <param name="noOfDays">The no of days.</param>
 /// <returns></returns>
 /// <exception cref="HotelReservationException">
 /// throws exception Hotel doesn't exist for invalid hotel name
 /// or
 /// throws exception Invalid Customer Type when wrong customer type is entered.
 /// </exception>
 public int HotelRentGenerator(HotelName name, CustomerType type, int regularDays, int weekendDays)
 {
     if (type.Equals(CustomerType.REGULAR))
     {
         if (name.Equals(HotelName.Lakewood))
         {
             regularRate = 110;
             weekendRate = 90;
             return(regularDays * regularRate + weekendDays * weekendRate);
         }
         if (name.Equals(HotelName.Bridgewood))
         {
             regularRate = 150;
             weekendRate = 50;
             return(regularDays * regularRate + weekendDays * weekendRate);
         }
         if (name.Equals(HotelName.Ridgewood))
         {
             regularRate = 220;
             weekendRate = 150;
             return(regularDays * regularRate + weekendDays * weekendRate);
         }
         else
         {
             throw new HotelReservationException(HotelReservationException.ExceptionType.NO_SUCH_HOTEL, "Hotel doesn't exist");
         }
     }
     if (type.Equals(CustomerType.REWARD))
     {
         if (name.Equals(HotelName.Lakewood))
         {
             regularRate = 80;
             weekendRate = 80;
             return(regularDays * regularRate + weekendDays * weekendRate);
         }
         if (name.Equals(HotelName.Bridgewood))
         {
             regularRate = 110;
             weekendRate = 50;
             return(regularDays * regularRate + weekendDays * weekendRate);
         }
         if (name.Equals(HotelName.Ridgewood))
         {
             regularRate = 100;
             weekendRate = 40;
             return(regularDays * regularRate + weekendDays * weekendRate);
         }
         else
         {
             throw new HotelReservationException(HotelReservationException.ExceptionType.NO_SUCH_HOTEL, "Hotel doesn't exist");
         }
     }
     else
     {
         throw new HotelReservationException(HotelReservationException.ExceptionType.NO_SUCH_CUSTOMER_TYPE, "Invalid Customer Type");
     }
 }
Ejemplo n.º 2
0
 public int ratingOfHotel;         // rating of hotels
 public HotelData(HotelName nameOfHotel, CustomerType customerType)
 {
     /* parameterized constructor
      * try-catch block checks for exception thrown by invalid hotel name
      */
     this.nameOfHotel = nameOfHotel;
     try
     {
         /* checking name of hotels
          * inner try-catch block to handle exceptions for invalid customer type
          * assigning weekday and weekend rates based on customer type
          */
         if (nameOfHotel.Equals(HotelName.LAKEWOOD))
         {
             this.ratingOfHotel = 3;
             try
             {
                 if (customerType.Equals(CustomerType.REGULAR))
                 {
                     this.weekDayRateOfHotel = 110; this.weekEndRateOfHotel = 90;
                 }
                 if (customerType.Equals(CustomerType.REWARD))
                 {
                     this.weekDayRateOfHotel = 80; this.weekEndRateOfHotel = 80;
                 }
             }
             catch (HotelReservationException)
             {
                 throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_CUSTOMER_TYPE, "Invalid Customer Type");
             }
         }
         if (nameOfHotel.Equals(HotelName.BRIDGEWOOD))
         {
             this.ratingOfHotel = 4;
             try
             {
                 if (customerType.Equals(CustomerType.REGULAR))
                 {
                     this.weekDayRateOfHotel = 150; this.weekEndRateOfHotel = 50;
                 }
                 if (customerType.Equals(CustomerType.REWARD))
                 {
                     this.weekDayRateOfHotel = 110; this.weekEndRateOfHotel = 50;
                 }
             }
             catch (HotelReservationException)
             {
                 throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_CUSTOMER_TYPE, "Invalid Customer Type");
             }
         }
         if (nameOfHotel.Equals(HotelName.RIDGEWOOD))
         {
             this.ratingOfHotel = 5;
             try
             {
                 if (customerType.Equals(CustomerType.REGULAR))
                 {
                     this.weekDayRateOfHotel = 220; this.weekEndRateOfHotel = 150;
                 }
                 if (customerType.Equals(CustomerType.REWARD))
                 {
                     this.weekDayRateOfHotel = 100; this.weekEndRateOfHotel = 40;
                 }
             }
             catch (HotelReservationException)
             {
                 throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_CUSTOMER_TYPE, "Invalid Customer Type");
             }
         }
     }
     catch (HotelReservationException)
     {
         throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_HOTEL_NAME, "Invalid Name of Hotel");
     }
 }