Advertisement
savovaap_

1.Library

May 24th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Library {
  4.     public Library(String name) {
  5.         this.name = name;
  6.         this.Books = new ArrayList<Book>();
  7.     }
  8.  
  9.     String name;
  10.     ArrayList<Book> Books;
  11.  
  12.     public String getName() {
  13.         return name;
  14.     }
  15.  
  16.     public void setName(String name) {
  17.         this.name = name;
  18.     }
  19.  
  20.     public ArrayList<Book> getBooks() {
  21.         return Books;
  22.     }
  23.  
  24.     public void setBooks(ArrayList<Book> Books) {
  25.         this.Books = Books;
  26.     }
  27.  
  28.     public void AddBook(Book book){
  29.         this.Books.add(book);
  30.     }
  31.  
  32.     public Book FindBookByAuthor(String author){
  33.         return Books.stream()
  34.                 .filter((Book) -> Book.getAuthor().equals(author))
  35.                 .findFirst()
  36.                 .orElse(null);
  37.     }
  38.  
  39.     public String BookInfo(Book book){
  40.         return "Title: " + book.getTitle() + "\n" + "Author: "
  41.         + book.getAuthor() + "\n" + "Publishing House: " + book.getPublishingHouse() + "\n"
  42.                 + "Date: " + book.getDate() + "\n" + "ISBN: " + book.getIsbn();
  43.     }
  44.  
  45.     public void RemoveBook(Book book){
  46.         if(!Books.contains(book)){
  47.             return;
  48.         }
  49.  
  50.         Books.remove(book);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement