Please implement the Book search(Object e). This method returns the object being search if not found return null

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

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<Book> books;

    
    public CollectionBooks() {
        books = new ArrayList<Book>();
    }

    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
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
Transcribed Image 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
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage