Advertisement
kagurasuki

hotel 29-05-2023

May 29th, 2023
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.94 KB | Source Code | 0 0
  1. class Hotel {
  2.   constructor (name, room, stay, member){
  3.     this.rooms = {
  4.       linux: {
  5.         standard: 150000,
  6.         medium: 200000,
  7.         vip: 300000
  8.     },
  9.       windows: {
  10.         standard: 200000,
  11.         medium: 250000,
  12.         vip: 350000
  13.       },
  14.       mac: {
  15.         standard: 250000,
  16.         medium: 300000,
  17.         vip: 1000000
  18.       }}
  19.     this.name = name;
  20.     this.room = room;
  21.     this.stay = stay;
  22.     this.member = member;
  23.  
  24.     this.getRates = () => this.rooms[this.room][this.roomType];
  25.   }
  26.   setRoomType(roomType){
  27.     this.roomType = roomType;
  28.   }
  29. }
  30.  
  31.                                                                                          let fancyBorder = [];                                                                    do {                                                                                       fancyBorder.push("=");
  32. }
  33. while (fancyBorder.length < 30);
  34. fancyBorder = fancyBorder.join(" ");
  35.  
  36. const linus = new Hotel("linus", "windows", 3, true);
  37. linus.setRoomType("vip");
  38.  
  39. const mark = new Hotel("mark", "mac", 8, false);
  40. mark.setRoomType("standard");
  41.  
  42. const gates = new Hotel("gates", "linux", 3, true);
  43. gates.setRoomType("medium");
  44.  
  45.  
  46. function getPayment(customer){
  47.   const {name, room, stay, member, roomType} = customer;
  48.   const rates = customer.getRates();
  49.  
  50.   const subTotal = stay * rates;
  51.   const memberDiscount = (member) ? .10 * subTotal : 0;
  52.   const stayDiscount = (stay > 3) ? .5 * (subTotal - memberDiscount) : 0;
  53.   const total = subTotal - memberDiscount - stayDiscount;
  54.  
  55.   console.log(`\n${fancyBorder}\nInformasi pelanggan hotel\n\nnama pelanggan: ${name}\nkamar: ${room}\nlama tinggal: ${stay} hari\nmember: ${member}\ntipe kamar: ${roomType}\ntarif: ${rates}\nsub total bayar: ${subTotal}\ndiskon member: ${memberDiscount}\ndiskon menginap: ${stayDiscount}\n\ntotal bayar: ${total}\n${fancyBorder}`);
  56. }
  57.  
  58.  
  59. getPayment(linus);
  60. getPayment(mark);
  61. getPayment(gates);
Tags: tmp iseng
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement