Define a Java class named \"Book\" in a package named \"BOOK\". This class has 5
ID: 3910240 • Letter: D
Question
Define a Java class named "Book" in a package named "BOOK". This class has 5 attributes: 1. ISBN number (an integer of 10 digits) 2. Title 3. Author (assumed that each book is authored by only one author) 4. Edition (e.g.: 1st Edition, 2nd Edition, etc.) 5. Publisher (e.g. Pearson, etc. ) All of them should be defined as private. Class Book definition provides a default constructor, get- methods and set-methods of the attributes, and a method to display book data in only one line PART II Write a Java program that can read data of a book from the console. The program should check to be sure that the ISBN input is a positive value and input values of title, author, edition, and publisher are not empty strings. The Java program should be another Java class named "BookDisplayer in the same package, i.e BOOK. The program creates an object of class Book. After reading the inputs, the program sets the values of the attributes of the Book object and invokes the public method of class Book to display the book data Important Notes. To submit PARTI, students copy all the code of the class Book into a Notepad file named "hw2 Book" (the file should have the suffix.txt) To submit PARTII, students copy all the code of the program BookDisplayer into a Notepad file named "hw2_BookDisplayer" (the file should have the suffix .txt) . . Example Output in the Console Enter ISBN of the book: 123 Enter title of the book: Java Programming Enter author of the book: Liang Enter edition of the book: 10 Enter publisher of the book: Pearson ISBN: 123; Title: Java Programming; Author Liang; Edition: 10 Publisher PearsonExplanation / Answer
public class Book { private int isbn; private String title, author; private int edition; private String publisher; public Book() { } public int getIsbn() { return isbn; } public void setIsbn(int isbn) { this.isbn = isbn; } 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 int getEdition() { return edition; } public void setEdition(int edition) { this.edition = edition; } public String getPublisher() { return publisher; } public void setPublisher(String publisher) { this.publisher = publisher; } public void display() { System.out.printf("ISBN: %d; Title: %s; Author: %s; Edition: %d; Publisher: %s ", isbn, title, author, edition, publisher); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.