Java programming Please implement the Book search(Object e) . This method returns the object being search if not found return null Initial code to be completed: public class CollectionBooks { private...



Java programming


Please implement the
Book 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);
    }
}










Define a class CollectionBooks. This class has a data member list of type Book using<br>the ArrayList collection.<br>Define method add. This method add the any object to list.<br>• Define printAll. This method display all the added object in the list.<br>• Define int count. This method returns the number of objects added in the list.<br>• Define Book search(Object e). This method returns the object being search if not found return null.<br>• Define void remove(int index). This method remove the object in a list<br>Add a main method with the following menu:<br>1- Add<br>2 - Count<br>3 - Print<br>4 - Search<br>5 - Delete<br>6 - Exit<br>

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

Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here