neZnam121

Untitled

Feb 19th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. class LibraryCollection{
  2.     constructor(capacity){
  3.         this.capacity=capacity;
  4.         this.books=[];
  5.     }
  6.     addBook (bookName, bookAuthor){
  7.         if(this.books.length > this.capacity){
  8.             throw Error('Not enough space in the collection.');
  9.         }else{
  10.  
  11.             let book={
  12.                 bookName:bookName,
  13.                 bookAuthor:bookAuthor,
  14.                 payed: false,
  15.             }
  16.  
  17.             this.books.push(book)
  18.  
  19.             return (`The ${bookName}, with an author ${bookAuthor}, collect.`)
  20.         }
  21.     }
  22.  
  23.     payBook( bookName ) {
  24.         if(!this.books.some(x => x.bookName == bookName)){
  25.             throw new Error(`${bookName} is not in the collection.`)
  26.         }
  27.         if (this.books.some(x => x.payed == true)) {
  28.          throw new Error(`${bookName} has already been paid.`)  
  29.         }else{
  30.            
  31.             let book = this.books.some(x => x.bookName == bookName);
  32.             this.book.payed = true;
  33.             return `${bookName} has been successfully paid.`;
  34.         }
  35.     }
  36.  
  37.     removeBook(bookName) {
  38.         if(!this.books.some(x => x.bookName == bookName)){
  39.             throw new Error(`The book, you're looking for, is not found.`);
  40.        }
  41.        if (this.books.some(x => x.payed == false)) {
  42.            throw new Error(`${bookName} need to be paid before removing from the collection.`);
  43.        }else{
  44.            this.books=this.books.filter(x => x.bookName != bookName);
  45.            return `${bookName} remove from the collection.`;
  46.        }
  47.    }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment