Q:

java book management system using ArrayList

0

Write a Java program to implement the following:

-        Ask the user to enter the names of 4 Books and store them in an ArrayList called Book.

-        Remove the first book from the list.

-        Ask the user to enter a new book name and store to be the second book of the list.

-        Ask the user to enter a book name, search for it in the list, and print “exist” or “not exist”.

-        Print the book name at index 3.

-        Print all list items using enhanced for and its size.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.*;

public class JavaApplication98 {

    public static void main(String[] args) {
         Scanner read = new Scanner(System.in);
        ArrayList<String> Book = new ArrayList<String>();
        String a;
        for(int i=0; i<5 ; i++){
            System.out.println("enter book name ");
            a = read.nextLine();
            Book.add(i, a);
        }
        Book.remove(0);
        
        System.out.println("enter new book name: ");
        String b = read.nextLine();
        Book.set(1, b);
        
        
        System.out.println("enter book name : ");
        String c = read.nextLine();
        boolean n = Book.contains(c);
        if(n){
           System.out.println("exist");
        } else{
            System.out.println(" not exist");
        }
      
         System.out.println( Book.get(3));
      
         for(String bookName:Book){
              System.out.println(bookName);
         }
System.out.println(Book.size());
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now