Ivankooo1

Hall

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