Advertisement
Guest User

Library

a guest
Apr 24th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Library {
  4.  
  5.     private ArrayList<Book> newBookedd = new ArrayList<Book>();
  6.  
  7.     public Library() {
  8.        
  9.     }
  10.  
  11.     public void addBook(Book newBook) {
  12.  
  13.           this.newBookedd.add(newBook);
  14.  
  15.     }
  16.  
  17.     public void printBooks() {
  18.  
  19.         for (Book i : this.newBookedd) {
  20.             System.out.println(i);
  21.         }
  22.  
  23.     }
  24.  
  25.     public ArrayList<Book> searchByTitle(String title) {
  26.         ArrayList<Book> found = new ArrayList<Book>();
  27.  
  28.         for (Book i : this.newBookedd) {
  29.             if (this.newBookedd.contains(title)) {
  30.                 //  System.out.println(i);
  31.                 found.add(i);
  32.  
  33.             } else {
  34.                 //do nothing
  35.             }
  36.  
  37.         }
  38.         System.out.println(found);
  39.         return found;
  40.     }
  41.  
  42.     public ArrayList<Book> searchByPublisher(String publisher) {
  43.         ArrayList<Book> found = new ArrayList<Book>();
  44.  
  45.         for (Book i : this.newBookedd) {
  46.             if (this.newBookedd.contains(publisher)) {
  47.                 found.add(i);
  48.             }
  49.         }
  50.         return found;
  51.     }
  52.  
  53.     public ArrayList<Book> searchByYear(int year) {
  54.  
  55.         ArrayList<Book> found = new ArrayList<Book>();
  56.  
  57.         for (Book i : this.newBookedd) {
  58.             if (this.newBookedd.contains(year)) {
  59.                 found.add(i);
  60.             }
  61.         }
  62.         return found;
  63.  
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement