Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Hotel {
  2.     constructor(name,capacity){
  3.         this.name = name;
  4.         this.capacity = capacity;
  5.         this.bookings = [];
  6.         this.currentBookingNumber = 0;
  7.         this.roomCont = {
  8.             single: parseInt(this.capacity / 2),
  9.             double: parseInt((this.capacity * 30) /100),
  10.             maisonette: parseInt((this.capacity * 20) /100)
  11.         }
  12.         this.roomNumber = 1;
  13.     }
  14.     get roomsPricing(){
  15.         return {
  16.             single: 50,
  17.             double: 90,
  18.             maisonette: 135
  19.         }
  20.     }
  21.  
  22.     get servicesPricing(){
  23.         return {
  24.             food:10,
  25.             drink:15,
  26.             housekeeping:25
  27.         }
  28.     }
  29.    
  30.     rentARoom(clientName,roomType,nights){
  31.         if(this.roomCont[roomType] > 0){
  32.             let currentBooking = {
  33.                 clientName,
  34.                 roomType,
  35.                 nights,
  36.                 bookingNumber : this.roomNumber++
  37.             }
  38.             this.bookings.push(currentBooking);
  39.             this.currentBookingNumber+=1;
  40.             this.roomCont[roomType] -=1;
  41.             return `Enjoy your time here Mr./Mrs. ${clientName}. Your booking is ${this.currentBookingNumber}.`;
  42.         }else{
  43.             let output = []
  44.             output.push(`No ${roomType} rooms available!`);
  45.             Object.entries(this.roomCont).map(x=> {
  46.                 if(x[1] > 0){
  47.                     output.push(`Available ${x[0]} rooms: ${x[1]}.`);
  48.                 }
  49.             })
  50.             return output.join(' ');
  51.         }
  52.     }
  53.     roomService(currentBookingNumber,serviceType){
  54.         let currentRoom = Object.values(this.bookings).find(x=> x.bookingNumber === currentBookingNumber)
  55.         if(currentRoom.length === 0){
  56.             return `The booking ${currentBookingNumber} is invalid.`
  57.         }
  58.         if(!this.servicesPricing[serviceType]){
  59.             return `We do not offer ${serviceType} service.`
  60.         }
  61.        if(!currentRoom.services){
  62.            currentRoom['services'] = []
  63.        }
  64.         currentRoom.services.push(serviceType);
  65.         return `Mr./Mrs. ${currentRoom.clientName}, Your order for ${serviceType} service has been successful.`
  66.  
  67.     }
  68.     checkOut(currentBookingNumber){
  69.         let currentRoom = Object.values(this.bookings).find(x=> x.bookingNumber === currentBookingNumber);
  70.         if(currentRoom.length === 0){
  71.             return `The booking ${currentBookingNumber} is invalid.`
  72.         }
  73.         let nightsTotal = currentRoom.nights * this.roomsPricing[currentRoom.roomType];
  74.         this.roomCont[currentRoom.roomType] +=1
  75.         if(currentRoom.services){
  76.            let adds = 0
  77.             currentRoom.services.forEach(x=>{
  78.                 adds += this.servicesPricing[x];
  79.                 nightsTotal += this.servicesPricing[x]
  80.             });
  81.             return `We hope you enjoyed your time here, Mr./Mrs. ${currentRoom.clientName}. The total amount of money you have to pay is ${nightsTotal} BGN. You have used additional room services, costing ${adds} BGN.`
  82.         }else{
  83.             return `"We hope you enjoyed your time here, Mr./Mrs. ${currentRoom.clientName}. The total amount of money you have to pay is ${nightsTotal} BGN."`
  84.         }
  85.        
  86.     }
  87.     report(){
  88.       let hotelName=  this.name
  89.       let output = [];
  90.       let k = ''
  91.       k +=  `${hotelName.toUpperCase()} DATABASE:\n${"-".repeat(20)}`
  92.       if(this.bookings.length === 0){
  93.           k += `\nThere are currently no bookings.`
  94.          
  95.       }else{
  96.         Object.values(this.bookings).forEach(x=>{
  97.             if(x.services){
  98.               output.push(`\nbookingNumber - ${x.bookingNumber}\nclientName - ${x.clientName}\nroomType - ${x.roomType}\nnights - ${x.nights}\nservices: ${x.services.join(', ')}`)
  99.             }else{
  100.  
  101.                 output.push(`\nbookingNumber - ${x.bookingNumber}\nclientName - ${x.clientName}\nroomType - ${x.roomType}\nnights - ${x.nights}\n`)
  102.             }
  103.  
  104.         })
  105.         k += output.join('-'.repeat(10))
  106.       }
  107.      
  108.        
  109.       return k
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement