コード例 #1
0
 /// <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");
     }
 }
コード例 #2
0
 public List <Hotel> AddHotel(CustomerType customerType)
 {
     if (customerType.Equals(CustomerType.reward))
     {
         hotels.Add(new Hotel("Lakewood", CustomerType.reward));
         hotels.Add(new Hotel("Bridgewood", CustomerType.reward));
         hotels.Add(new Hotel("Ridgewood", CustomerType.reward));
     }
     else
     {
         AddHotel();
     }
     return(hotels);
 }
コード例 #3
0
        public CartCalculator(Dictionary <Product, int> cart, CustomerType customerType, Region region)
        {
            this.cart         = cart;
            this.customerType = customerType;
            this.region       = region;

            if (customerType.Equals(CustomerType.Standard))
            {
                this.tax = 19;
            }
            else
            {
                this.tax = 0;
            }
        }
コード例 #4
0
 /// <summary>
 /// Assigns values to weekend and weekday rates to hotels as per cutomer type: regular or reward
 /// </summary>
 /// <param name="hotelName"></param>
 /// <param name="customerType"></param>
 public Hotel(string hotelName, CustomerType customerType)
 {
     this.mNameOfHotel = hotelName;
     if (customerType.Equals(CustomerType.regular))
     {
         if (this.mNameOfHotel == "Lakewood")
         {
             this.mRegularWeekdayRate = 110;
             this.mRegularWeekendRate = 90;
             this.mrating             = 3;
         }
         if (this.mNameOfHotel == "Bridgewood")
         {
             this.mRegularWeekdayRate = 160;
             this.mRegularWeekendRate = 60;
             this.mrating             = 4;
         }
         if (this.mNameOfHotel == "Ridgewood")
         {
             this.mRegularWeekdayRate = 220;
             this.mRegularWeekendRate = 150;
             this.mrating             = 5;
         }
     }
     else
     {
         if (this.mNameOfHotel == "Lakewood")
         {
             this.mRegularWeekdayRate = 80;
             this.mRegularWeekendRate = 80;
             this.mrating             = 3;
         }
         if (this.mNameOfHotel == "Bridgewood")
         {
             this.mRegularWeekdayRate = 110;
             this.mRegularWeekendRate = 50;
             this.mrating             = 4;
         }
         if (this.mNameOfHotel == "Ridgewood")
         {
             this.mRegularWeekdayRate = 100;
             this.mRegularWeekendRate = 40;
             this.mrating             = 5;
         }
     }
 }
コード例 #5
0
 public Hotel(HotelType hotelType, CustomerType customerType)
 {
     this.type = hotelType;
     try
     {
         if (hotelType.Equals(HotelType.LAKEWOOD))
         {
             this.RATING = 3;
             try
             {
                 if (customerType.Equals(CustomerType.NORMAL))
                 {
                     this.WEEKDAY_RATE = 110;
                     this.WEEKEND_RATE = 90;
                 }
                 if (customerType.Equals(CustomerType.REWARD))
                 {
                     this.WEEKDAY_RATE = 80;
                     this.WEEKEND_RATE = 80;
                 }
             }
             catch (HotelReservationException)
             {
                 throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_CUSTOMER_TYPE, "Invalid customer type");
             }
         }
         if (hotelType.Equals(HotelType.BRIDGEWOOD))
         {
             this.RATING = 4;
             try
             {
                 if (customerType.Equals(CustomerType.NORMAL))
                 {
                     this.WEEKDAY_RATE = 150;
                     this.WEEKEND_RATE = 50;
                 }
                 if (customerType.Equals(CustomerType.REWARD))
                 {
                     this.WEEKDAY_RATE = 110;
                     this.WEEKEND_RATE = 50;
                 }
             }
             catch (HotelReservationException)
             {
                 throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_CUSTOMER_TYPE, "Invalid customer type");
             }
         }
         if (hotelType.Equals(HotelType.RIDGEWOOD))
         {
             this.RATING = 5;
             try
             {
                 if (customerType.Equals(CustomerType.NORMAL))
                 {
                     this.WEEKDAY_RATE = 220;
                     this.WEEKEND_RATE = 150;
                 }
                 if (customerType.Equals(CustomerType.REWARD))
                 {
                     this.WEEKDAY_RATE = 100;
                     this.WEEKEND_RATE = 40;
                 }
             }
             catch (Exception)
             {
                 throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_CUSTOMER_TYPE, "Invalid customer type");
             }
         }
     }
     catch (HotelReservationException)
     {
         throw new HotelReservationException(HotelReservationException.ExceptionType.INVALID_HOTEL_TYPE, "Invalid Hotel Type");
     }
 }
コード例 #6
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");
     }
 }