Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Library {
- private ArrayList<Book> newBookedd = new ArrayList<Book>();
- public Library() {
- }
- public void addBook(Book newBook) {
- this.newBookedd.add(newBook);
- }
- public void printBooks() {
- for (Book i : this.newBookedd) {
- System.out.println(i);
- }
- }
- public ArrayList<Book> searchByTitle(String title) {
- ArrayList<Book> found = new ArrayList<Book>();
- for (Book i : this.newBookedd) {
- if (this.newBookedd.contains(title)) {
- // System.out.println(i);
- found.add(i);
- } else {
- //do nothing
- }
- }
- System.out.println(found);
- return found;
- }
- public ArrayList<Book> searchByPublisher(String publisher) {
- ArrayList<Book> found = new ArrayList<Book>();
- for (Book i : this.newBookedd) {
- if (this.newBookedd.contains(publisher)) {
- found.add(i);
- }
- }
- return found;
- }
- public ArrayList<Book> searchByYear(int year) {
- ArrayList<Book> found = new ArrayList<Book>();
- for (Book i : this.newBookedd) {
- if (this.newBookedd.contains(year)) {
- found.add(i);
- }
- }
- return found;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement