Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hotel {
- constructor(name,capacity){
- this.name = name;
- this.capacity = capacity;
- this.bookings = [];
- this.currentBookingNumber = 0;
- this.roomCont = {
- single: parseInt(this.capacity / 2),
- double: parseInt((this.capacity * 30) /100),
- maisonette: parseInt((this.capacity * 20) /100)
- }
- this.roomNumber = 1;
- }
- get roomsPricing(){
- return {
- single: 50,
- double: 90,
- maisonette: 135
- }
- }
- get servicesPricing(){
- return {
- food:10,
- drink:15,
- housekeeping:25
- }
- }
- rentARoom(clientName,roomType,nights){
- if(this.roomCont[roomType] > 0){
- let currentBooking = {
- clientName,
- roomType,
- nights,
- bookingNumber : this.roomNumber++
- }
- this.bookings.push(currentBooking);
- this.currentBookingNumber+=1;
- this.roomCont[roomType] -=1;
- return `Enjoy your time here Mr./Mrs. ${clientName}. Your booking is ${this.currentBookingNumber}.`;
- }else{
- let output = []
- output.push(`No ${roomType} rooms available!`);
- Object.entries(this.roomCont).map(x=> {
- if(x[1] > 0){
- output.push(`Available ${x[0]} rooms: ${x[1]}.`);
- }
- })
- return output.join(' ');
- }
- }
- roomService(currentBookingNumber,serviceType){
- let currentRoom = Object.values(this.bookings).find(x=> x.bookingNumber === currentBookingNumber)
- if(currentRoom.length === 0){
- return `The booking ${currentBookingNumber} is invalid.`
- }
- if(!this.servicesPricing[serviceType]){
- return `We do not offer ${serviceType} service.`
- }
- if(!currentRoom.services){
- currentRoom['services'] = []
- }
- currentRoom.services.push(serviceType);
- return `Mr./Mrs. ${currentRoom.clientName}, Your order for ${serviceType} service has been successful.`
- }
- checkOut(currentBookingNumber){
- let currentRoom = Object.values(this.bookings).find(x=> x.bookingNumber === currentBookingNumber);
- if(currentRoom.length === 0){
- return `The booking ${currentBookingNumber} is invalid.`
- }
- let nightsTotal = currentRoom.nights * this.roomsPricing[currentRoom.roomType];
- this.roomCont[currentRoom.roomType] +=1
- if(currentRoom.services){
- let adds = 0
- currentRoom.services.forEach(x=>{
- adds += this.servicesPricing[x];
- nightsTotal += this.servicesPricing[x]
- });
- 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.`
- }else{
- return `"We hope you enjoyed your time here, Mr./Mrs. ${currentRoom.clientName}. The total amount of money you have to pay is ${nightsTotal} BGN."`
- }
- }
- report(){
- let hotelName= this.name
- let output = [];
- let k = ''
- k += `${hotelName.toUpperCase()} DATABASE:\n${"-".repeat(20)}`
- if(this.bookings.length === 0){
- k += `\nThere are currently no bookings.`
- }else{
- Object.values(this.bookings).forEach(x=>{
- if(x.services){
- output.push(`\nbookingNumber - ${x.bookingNumber}\nclientName - ${x.clientName}\nroomType - ${x.roomType}\nnights - ${x.nights}\nservices: ${x.services.join(', ')}`)
- }else{
- output.push(`\nbookingNumber - ${x.bookingNumber}\nclientName - ${x.clientName}\nroomType - ${x.roomType}\nnights - ${x.nights}\n`)
- }
- })
- k += output.join('-'.repeat(10))
- }
- return k
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement