Question: JAVA Using Scanner and the for loop statement, define a method that reads in the ISBN of a book and deletes the corresponding Book from

JAVA

Using Scanner and the for loop statement, define a method that reads in the ISBN of a book and deletes the corresponding Book from the ArrayList. The method should return true if the book is deleted and false if it is not (if a book with the ISBN does not exist in the ArrayList). NOTE: Do not change anything in the class provided.

public class Book {

private String title;

private String author;

private String ISBN;

private double RRP;

public Book(String t, String a, String ISBN, double RRP) {

this.title = t;

this.author = a;

this.ISBN = ISBN;

this.RRP = RRP;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public String getAuthor() {

return author;

}

public void setAuthor(String author) {

this.author = author;

}

public String getISBN() {

return ISBN;

}

public void setISBN(String ISBN) {

this.ISBN = ISBN;

}

public double getRRP() {

return RRP;

}

public void setRRP(double RRP) {

this.RRP = RRP;

}

@Override

public String toString() {

return "Book [title=" + title + ", author=" + author + ", ISBN=" + ISBN + ", RRP=" + RRP + "]";

}

}

-------------------------------

import java.util.ArrayList;

import java.util.Scanner;

public class MyClass {

public static void main(String[] args) {

ArrayList myList = new ArrayList();

Scanner sc = new Scanner(System.in);

for (int i = 0; i < 4; i++) {

System.out.println("Enter the book title: ");

String title = sc.next();

System.out.println("Enter the author of the book: ");

String author = sc.next();

System.out.println("Enter ISBN: ");

String ISBN = sc.next();

System.out.println("Enter RRP: ");

double RRP = sc.nextDouble();

Book b = new Book(title, author, ISBN, RRP);

myList.add(b);

Display(myList);

}

sc.close();

}

public static void Display(ArrayList display) {

for (int i = 0; i < display.size(); i++) {

System.out.println(display.get(i));

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!