Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

Students also viewed these Databases questions