Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hotel {
- constructor (name, room, stay, member){
- this.rooms = {
- linux: {
- standard: 150000,
- medium: 200000,
- vip: 300000
- },
- windows: {
- standard: 200000,
- medium: 250000,
- vip: 350000
- },
- mac: {
- standard: 250000,
- medium: 300000,
- vip: 1000000
- }}
- this.name = name;
- this.room = room;
- this.stay = stay;
- this.member = member;
- this.getRates = () => this.rooms[this.room][this.roomType];
- }
- setRoomType(roomType){
- this.roomType = roomType;
- }
- }
- let fancyBorder = []; do { fancyBorder.push("=");
- }
- while (fancyBorder.length < 30);
- fancyBorder = fancyBorder.join(" ");
- const linus = new Hotel("linus", "windows", 3, true);
- linus.setRoomType("vip");
- const mark = new Hotel("mark", "mac", 8, false);
- mark.setRoomType("standard");
- const gates = new Hotel("gates", "linux", 3, true);
- gates.setRoomType("medium");
- function getPayment(customer){
- const {name, room, stay, member, roomType} = customer;
- const rates = customer.getRates();
- const subTotal = stay * rates;
- const memberDiscount = (member) ? .10 * subTotal : 0;
- const stayDiscount = (stay > 3) ? .5 * (subTotal - memberDiscount) : 0;
- const total = subTotal - memberDiscount - stayDiscount;
- 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}`);
- }
- getPayment(linus);
- getPayment(mark);
- getPayment(gates);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement