Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Movie {
- constructor(movieName, ticketPrice) {
- this.movieName = movieName;
- this.ticketPrice = ticketPrice;
- this.screenings = [];
- this.totalProfit=0;
- this.ticketCount=0;
- }
- newScreening(date, hall, description) {
- if (this.screenings.find(s => s.date === date && s.hall === hall)) {
- throw new Error(`Sorry, ${hall} hall is not available on ${date}`);
- }else {
- this.screenings.push({date, hall, description})
- return `New screening of ${this.movieName} is added.`;
- }
- }
- endScreening(date,hall,soldTickets){
- let isScreeningFind=this.screenings.find(s=>s.date===date && s.hall===hall)
- if(isScreeningFind===undefined){
- throw new Error(`Sorry, there is no such screening for ${this.movieName} movie.`)
- }else {
- let profit=Number(soldTickets)*Number(this.ticketPrice);
- this.ticketCount+=soldTickets;
- this.totalProfit+=profit;
- let index=0;
- for(let i=0;i<this.screenings.length;i++){
- if(this.screenings[i].date===date && this.screenings[i]===hall){
- index=i;
- break;
- }
- }
- this.screenings.splice(index,1);
- return `${this.movieName} movie screening on ${date} in ${hall} hall has ended. Screening profit: ${profit}`;
- }
- }
- toString(){
- let output=[
- `${this.movieName} full information:`,
- `Total profit: ${this.totalProfit.toFixed(0)}$`,
- `Sold Tickets: ${this.ticketCount}`,
- ]
- if(this.screenings.length<0){
- output.push('No more screenings!');
- }
- output.push('Remaining film screenings:');
- let sorted= this.screenings.sort((a,b)=>a.hall.localeCompare(b.hall))
- sorted.forEach((s)=>{
- output.push(`${s.hall} - ${s.date} - ${s.description}`)
- })
- return output.join('\n');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement