JAVA PROGRAMMING HELP ME! PLEASE MAKE THIS PROGRAM RUN, I' HAVING HARD TIME TO FIX IT PLEASE. I WILL RATE YOU VERY GOOD, THANK YOU SO MUCH! SEE ATTACHED PHOTO FOR THE INSTRUCTIONS OR GUIDE

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question

JAVA PROGRAMMING

HELP ME! PLEASE MAKE THIS PROGRAM RUN, I' HAVING HARD TIME TO FIX IT PLEASE. I WILL RATE YOU VERY GOOD, THANK YOU SO MUCH! SEE ATTACHED PHOTO FOR THE INSTRUCTIONS OR GUIDE

import java.util.*;
public class TestMain {

    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("Menu:-\n1 – Add\n2 – Count\n3 – Print\n4 – Search\n5 – Delete\n6 - Exit");
        Scanner sc = new Scanner(System.in);
        int menuId=0;
        CollectionBooks m = new CollectionBooks();
        
        while (menuId!=6){
            System.out.print("Your choice: ");
            menuId=sc.nextInt();
            
            switch(menuId){
                case 1 :
                    System.out.print("Add-Book Id: ");
                    int bookId=sc.nextInt();
                    System.out.print("Add-Book Name: ");
                    sc.nextLine();
                    String book=sc.nextLine();
                    m.add(book,bookId);
                break; 
                    
                case 2:
                    System.out.println("Count= "+m.count());
                break;
                
                case 3:
                    m.printAll();
                break;
                
                case 4:
                    sc.nextLine();
                    System.out.println("Search Book: ");
                    String bookName=sc.nextLine();
                    Book b=new Book();
                    b.setName(bookName);
                    Book n=m.search(b);
                    System.out.println("BookName : "+n.getName()+" \nBook Id: "+n.getId());
                break;
                
                case 5:
                    System.out.println("Remove index: ");
                    m.remove(sc.nextInt());
                break;
            default:
            System.out.println("Invalid Input ");
            }
        }
    }
}

public class Book {
    String name;
    int id;
    
    public Book() {
        
    }

    public Book(String name, int id) {
        this.name = name;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setId(int id) {
        this.id=id;
    }
    
    public void setName(String name){
        this.name=name;
    }

    public int getId() {
        return id;
    }
}

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){
        for(Book b:books) {
            if(b.equals(e)) 
            return b;     
        }
        return null;    
    }
    
    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 4 steps with 4 images

Blurred answer
Knowledge Booster
JQuery and Javascript
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning