Java Program using Linked List : <p>I am making a program in which the program shows some options like insert Book, delete Book etc. The program asks us to enter certain details about a book by Insert method.</p>

<p>I have made every method but I have no any idea of how to make a delete method. It's my assignment in class. First of all I am very very weak in programming and especially in linked list. So any help regarding delete method will be appreciated. Here is my code...</p>

<pre><code>import java.util.Scanner;

public class BookApplication {
static Book head, pointer;
static Scanner scan = new Scanner(System.in);

public static void main(String[] args) {
    System.out.println("Welcome to Smart Book Store");
    System.out.println("Please choose an option from the list below");
    int choice = 0;
    do {

        System.out.println("1. Insert Book\n2. Delete Book\n3. Search Book\n4. Update Book\n5. View Book\n6. Exit");
        choice = scan.nextInt();
        try {
            choice = Integer.parseInt(scan.nextLine());
        } catch (Exception e) {
            switch (choice) {
            case 1:

                addBook();
                break;
            case 2:

            case 3:
                searchBook();
                break;
            case 4:
                updateBook();
                viewBook();
                break;
            case 5:
                viewBook();
                break;
            case 6:
                scan.close();
                System.exit(0);
                break;
            default:
                System.out.println("Please choose from 1 to 5");
                break;

            }
        }

    } while (true);
}

static void addBook() {
    if (head == null) {
        String details[] = enterDetails();
        pointer = new Book(details[0], details[1], details[2]);
        head = pointer;
        pointer.next = null;
    } else {
        String details[] = enterDetails();

        pointer.next = new Book(details[0], details[1], details[2]);
        pointer = pointer.next;
    }
}

static String[] enterDetails() {
    String[] details = new String[4];
    try {

        String title;
        String ISBN;
        String authors;

        System.out.println("Please enter Book title");
        title = scan.nextLine();

        System.out.println("Please enter ISBN of book");
        ISBN = scan.nextLine();

        System.out.println("Please enter book's Author(s)");
        authors = scan.nextLine();

        details[0] = title;
        details[1] = ISBN;
        details[2] = authors;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return details;
}

private static void searchBook() {
    System.out.println();
    System.out.println("1. Search by TITLE");
    System.out.println("2. Search by ISBN");
    System.out.println("3. Search by AUTHOR");

    int choice = 0;
    choice: try {
        choice = Integer.parseInt(scan.nextLine());
    } catch (Exception e) {
        System.out.println();
        System.out.println("PLEASE ENTER VALUE BETWEEN 1 - 3");
        break choice;
    }

    switch (choice) {
    case 1:
        System.out.println("Please enter Title of BOOK");
        String title = scan.nextLine();
        if (head == null) {
            System.out.println("List is EMPTY !");
            return;
        } else {
            System.out.println();
            System.out.println("BOOK(S) IN THE SYSTEM ARE: ");
            System.out.println();
            pointer = head;
            while (pointer != null) {
                if (pointer.getTitle().equals(title)) {
                    System.out.println(pointer.getBook());

                }
                pointer = pointer.next;
            }
        }
        break;
    case 2:
        System.out.println("Please enter ISBN of BOOK");
        String ISBN = scan.nextLine();
        if (head == null) {
            System.out.println("List is EMPTY !");
            return;
        } else {
            System.out.println();
            System.out.println("BOOK(S) IN THE SYSTEM ARE: ");
            System.out.println();
            pointer = head;
            while (pointer != null) {
                if (pointer.getISBN().equals(ISBN)) {
                    System.out.println(pointer.getBook());
                    break;
                }
                pointer = pointer.next;
            }
        }
        break;
    case 3:
        System.out.println("Please enter Author(s) of BOOK");
        String authors = scan.nextLine();
        if (head == null) {
            System.out.println("List is EMPTY !");
            return;
        } else {
            System.out.println();
            System.out.println("BOOK(S) IN THE SYSTEM ARE: ");
            System.out.println();
            pointer = head;
            while (pointer != null) {
                if (pointer.getAuthors().contains(authors)) {
                    System.out.println(pointer.getBook());
                    break;
                }
                pointer = pointer.next;
            }
        }
        break;
    default:
        System.out.println("PLEASE ENTER VALUE BETWEEN 1 - 5");
    }

}

static void updateBook() {
    System.out.println();
    System.out.println("1. Update by TITLE");
    System.out.println("2. Update by ISBN");
    System.out.println("3. Update by AUTHOR");

    int choice = 0;
    choice: try {
        choice = Integer.parseInt(scan.nextLine());
    } catch (Exception e) {
        System.out.println();
        System.out.println("PLEASE ENTER VALUE BETWEEN 1 - 3");
        break choice;
    }
    switch (choice) {
    case 1:
        System.out.println("Please provide the Title of Book you want to update: ");
        String another1 = scan.nextLine();
        if (head == null) {
            System.out.println("No Books to Update");
            return;
        } else {
            Boolean found = false;

            pointer = head;
            while (!found &amp; pointer != null) {
                if (pointer.getTitle().equals(another1)) {
                    found = true;
                    System.out.println("Here is the current book:" + pointer.getBook());
                    System.out.println("Please enter the new Title:");
                    pointer.setTitle(scan.nextLine());
                    System.out.println("Please Enter the new ISBN:");
                    pointer.setISBN(scan.nextLine());
                    System.out.println("Please Enter the new Author:");
                    pointer.setAuthors(scan.nextLine());
                }
                pointer = pointer.next;
            }
        }

        break;
    case 2:

        System.out.println("Please provide the ISBN of Book you want to update: ");
        String ISBN = scan.nextLine();
        if (head == null) {
            System.out.println("No Books to Update!");
            return;
        } else {
            Boolean found = false;
            pointer = head;
            while (!found &amp;&amp; pointer != null) {
                if (pointer.getISBN().equals(ISBN)) {
                    found = true;
                    System.out.println("Here is the current book:" + pointer.getBook());
                    System.out.println("Please enter the new Title:");
                    pointer.setTitle(scan.nextLine());
                    System.out.println("Please Enter the new ISBN:");
                    pointer.setISBN(scan.nextLine());
                    System.out.println("Please Enter the new Author:");
                    pointer.setAuthors(scan.nextLine());
                }
                pointer = pointer.next;
            }
        }
    case 3:
        System.out.println("Please enter Author(s) of the Book you want to Update: ");

        String upauthor1 = scan.nextLine();
        if (head == null) {
            System.out.println("List is EMPTY !");
            return;
        } else {
            Boolean found = false;
            pointer = head;
            while (!found &amp;&amp; pointer != null) {
                if (pointer.getAuthors().contains(upauthor1)) {
                    found = true;
                    System.out.println("Here is the current book:" + pointer.getBook());
                    System.out.println("Please enter the new Title:");
                    pointer.setTitle(scan.nextLine());
                    System.out.println("Please Enter the new ISBN:");
                    pointer.setISBN(scan.nextLine());
                    System.out.println("Please Enter the new Author:");
                    pointer.setAuthors(scan.nextLine());
                }
                pointer = pointer.next;

            }
            break;
        }
    }

}

private static void viewBook() {

    Book element = head;

    System.out.println();
    System.out.println("Printing List");

    while (element != null) {
        System.out.println(element.getBook());
        element = element.next;
    }

    System.out.println("Book Printing Ended");
    System.out.println();
}

private static void deleteBook() {
    System.out.println();
    System.out.println("1. Delete by Title");
    System.out.println("2. Delete by ISBN");
    System.out.println("3. Delete by Author(s)");


        }


}
</code></pre>

<p>As you can see I have left delete Method blank because I have no idea how to delete a specific book which is inserted in the beginning of compilation.</p>

<p>Here is my Book class</p>

<pre><code>public class Book {


private String authors;
private String ISBN;
private String title;
public Book next;

Book(String title, String ISBN, String authors) {
    this.title = title;

    this.authors = authors;
    this.ISBN = ISBN;
}



public String getAuthors() {
    return authors;
}

public void setISBN(String ISBN){
    this.ISBN = ISBN;
}

public void setTitle(String title){
    this.title = title;
}

public void setAuthors(String authors) {
    this.authors = authors;
}



public String getISBN() {
    return ISBN;
}



public String getTitle() {
    return title;
}



public String getBook() {
    return "Book [authors=" + authors + ", ISBN=" + ISBN + ", title="+ title + "]";
}
</code></pre>

<p>}</p>
