Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.1 kB
1
Indexable
Never
/// ksiazka
class Book{
  title;
  author;
  numberOfPages;
  currentPage = 0;
  bookMark;
  is_borrowed = false; // true or false
  id;
  borrowed_by;  //Person
  
  constructor(title, author, numberOfPages, id){
    this.title =title;
    this.author = author;
    this.numberOfPages = numberOfPages;
    this.id = id;
  }
  
  nextPage(){
    if (this.currentPage === this.numberOfPages){
      console.log("Skonczyles ksiazke!")
    }else{
      this.currentPage++;
    }
  }
  
  prevPage(){
    if(this.currentPage >0){
      this.currentPage--;
    }else{
      console.log("nie ma takiej strony")
    }
  }
  
  goToPage(pageNumber){
    if (pageNumber <= this.numberOfPages && pageNumber >= 0){
      this.currentPage = pageNumber
    }else{
      console.log("nie ma takiej strony")
    }
  }
  
  addBookMark(pageNumber){
    if(pageNumber <= this.numberOfPages && pageNumber >= 0){
      this.bookMark = pageNumber
    }else{
      console.log("nie ma takiej strony")
    }
  }
  
}

// ksiegarnia
class Bookstore{
  name;
  list_of_books = [];

  constructor(name){
    this.name = name
  }
  
  addBook(book){
    this.list_of_books.push(book)
  }
  
  printBookList(){
    console.log(this.list_of_books)
  }
  
  
  borrowBook(id, client){
    book = this.list_of_books.find(book => book.id === id);
    book.is_borrowed = true;
    book.borrowed_by = client;
  }
  
  
  printBorrowedBooks(){
    console.log(this.list_of_books.filter(book => book.is_borrowed))
  }
  
  
  
}


class Person{
  name;
  lastName;
  
  constructor(name, lastName){
    this.name = name;
    this.lastName = lastName;
  }
}

client = new Person("Albin", "hyt")
ksiegarnia = new Bookstore("Albinoteka")



/////
book = new Book('Harry Potter', "Rowling", 500, 1)
book2 = new Book('50 twarzy greya', "Świstak", 255, 2)
book3 = new Book('Biblia', "Jezus", 1000, 3)
book4 = new Book('Czarny Łabędź', "Taleb", 755, 4)


ksiegarnia.addBook(book)
ksiegarnia.addBook(book2)
ksiegarnia.addBook(book3)
ksiegarnia.addBook(book4)

x=ksiegarnia.borrowBook(3, client)

ksiegarnia.printBorrowedBooks()