kstoyanov

02. Hall - JS Exam- 12 Aug 2020

Oct 9th, 2020 (edited)
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solveClasses() {
  2.     class Hall {
  3.         constructor(capacity, name) {
  4.             this.capacity = capacity;
  5.             this.name = name;
  6.             this.events = [];
  7.         }
  8.  
  9.         hallEvent(title) {
  10.             if (this.events.includes(title)) {
  11.                 throw new Error("This event is already added!");
  12.             }
  13.  
  14.             this.events.push(title);
  15.             return "Event is added.";
  16.         }
  17.  
  18.         close() {
  19.             this.events = [];
  20.             return `${this.name} hall is closed.`
  21.         }
  22.  
  23.         toString() {
  24.             const result = [`${this.name} hall - ${this.capacity}`];
  25.  
  26.             if (this.events.length > 0) {
  27.                 result.push(`Events: ${this.events.join(', ')}`);
  28.             }
  29.  
  30.             return result.join('\n');
  31.         }
  32.     }
  33.  
  34.     class MovieTheater extends Hall {
  35.         constructor(capacity, name, screenSize) {
  36.             super(capacity, name);
  37.             this.events = [];
  38.  
  39.             this.screenSize = screenSize;
  40.         }
  41.  
  42.         close() {
  43.             return super.close() + "Аll screenings are over.";
  44.         }
  45.  
  46.         toString() {
  47.             const result = [super.toString()];
  48.  
  49.             result.push(`${this.name} is a movie theater with ${this.screenSize} screensize and ${this.capacity} seats capacity.`);
  50.  
  51.             return result.join('\n');
  52.         }
  53.     }
  54.  
  55.     class ConcertHall extends Hall {
  56.         constructor(capacity, name) {
  57.             super(capacity, name);
  58.             this.events = [];
  59.             this.performers = []
  60.         }
  61.  
  62.         hallEvent(title, performers) {
  63.             if (this.events.includes(title)) {
  64.                 throw new Error("This event is already added!");
  65.             }
  66.  
  67.             this.events.push(title);
  68.             this.performers.push(...performers);
  69.  
  70.             return "Event is added.";
  71.         }
  72.  
  73.         close() {
  74.             this.performers = [];
  75.             return super.close() + "Аll performances are over.";
  76.         }
  77.  
  78.         toString() {
  79.             const result = [super.toString()];
  80.  
  81.             if (this.performers.length > 0) {
  82.                 result.push(`Performers: ${this.performers.join(', ')}.`);
  83.             }
  84.  
  85.             return result.join('\n');
  86.         }
  87.     }
  88.  
  89.     return {
  90.         Hall,
  91.         MovieTheater,
  92.         ConcertHall
  93.     }
  94. }
Add Comment
Please, Sign In to add comment