Java programming
Please implement theBook search(Object e). This method returns the object being search if not found return null
Initial code to be completed:
public class CollectionBooks { private ArrayList books; public CollectionBooks() { books = new ArrayList(); } public void add(String book,int bookId) { Book b=new Book(book,bookId); books.add(b); } public void printAll() { for(Book b:books){ System.out.println("Book Id: "+b.getId()); System.out.println("Book Name: "+b.getName()); } } public int count(){ return books.size(); }public Book search(Object e){ //your code here } public void remove(int index) { books.remove(index); }}Extracted text: Define a class CollectionBooks. This class has a data member list of type Book using the ArrayList collection. Define method add. This method add the any object to list. • Define printAll. This method display all the added object in the list. • Define int count. This method returns the number of objects added in the list. • Define Book search(Object e). This method returns the object being search if not found return null. • Define void remove(int index). This method remove the object in a list Add a main method with the following menu: 1- Add 2 - Count 3 - Print 4 - Search 5 - Delete 6 - Exit
public CollectionBooks() { books = new ArrayList(); } public void add(String book,int bookId) { Book b=new Book(book,bookId); books.add(b); } public void printAll() { for(Book b:books){ System.out.println("Book Id: "+b.getId()); System.out.println("Book Name: "+b.getName()); } } public int count(){ return books.size(); }public Book search(Object e){ //your code here } public void remove(int index) { books.remove(index); }}Extracted text: Define a class CollectionBooks. This class has a data member list of type Book using the ArrayList collection. Define method add. This method add the any object to list. • Define printAll. This method display all the added object in the list. • Define int count. This method returns the number of objects added in the list. • Define Book search(Object e). This method returns the object being search if not found return null. • Define void remove(int index). This method remove the object in a list Add a main method with the following menu: 1- Add 2 - Count 3 - Print 4 - Search 5 - Delete 6 - Exit
public void add(String book,int bookId) { Book b=new Book(book,bookId); books.add(b); } public void printAll() { for(Book b:books){ System.out.println("Book Id: "+b.getId()); System.out.println("Book Name: "+b.getName()); } } public int count(){ return books.size(); }public Book search(Object e){ //your code here } public void remove(int index) { books.remove(index); }}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here