Some of the characteristics of a book are the title, author(s), publisher, ISBN,
ID: 3660756 • Letter: S
Question
Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year of publication. Design a class Book that defines the book as an ADT. i. Each object of the class Book can hold the following information about a book: title, up to four authors, publisher, ISBN, price, year of publication, and number of copies in stock. To keep track of the number of authors, add another instance variable. ii. Include the methods to perform various operations on objects of Book. For example, the usual operations that can be performed on the title are to show the title, set the title, and check whether a title is the actual title of the book. Similarly, the typical operations that can be performed on the number of copies in stock are to show the number of copies in stock, set the number of copies in stock, update the number of copies in stock, and return the number of copies in stock. Add similar operations for the publisher, ISBN, book price, and authors. Add the appropriate constructors. b. Write the definitions of the methods the class Book. c. Write a program that uses the class Book and tests various operations on the objects of the class Book. Declare an array of 100 components of type Book. Some of the operations that you should perform are to search for a book by its title, search by ISBN, and update the number of copies of a book.Explanation / Answer
import java.util.ArrayList;
import java.util.Vector;
public class TestBook {
public void main(String args[]) {
Book book = new Book("JAVAPROG","Ravi" ,"CRAMSTER","ÏSBN", "$22.08", "2012", 1);
ArrayList<Book> books = new ArrayList<Book>(100) ;
}
}
public class Book {
private String title;
private ArrayList<String> authors = new ArrayList<String>(); //upto 4 authors
private String publisher;
private String ISBN;
private String price;
private String yearOfPublication;
private int copiesInStock;
public Book() {
}
public Book ( String title, String author,String publisher,String ISBN,String price, String yearOfPublication,int copiesInStock ) {
this.title = title;
this.addAuthors(author);
this.publisher =publisher;
this.ISBN =ISBN ;
this.price = price;
this.yearOfPublication = yearOfPublication;
this.copiesInStock =copiesInStock ;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthors() {
return authors.toString();
}
public void addAuthors(String authorName) {
if(this.authors.size() < 4) //upto 4 authors only
this.authors.add(authorName);
}
public String getPublisher() {
return publisher;
}
public void updatePublisher(String publisher) {
this.publisher = publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getISBN() {
return ISBN;
}
public void updateISBN(String iSBN) {
ISBN = iSBN;
}
public void setISBN(String iSBN) {
ISBN = iSBN;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public void updatePrice(String price) {
this.price = price;
}
public String getYearOfPublication() {
return yearOfPublication;
}
public void setYearOfPublication(String yearOfPublication) {
this.yearOfPublication = yearOfPublication;
}
public void updateYearOfPublication(String yearOfPublication) {
this.yearOfPublication = yearOfPublication;
}
public int getCopiesInStock() {
return copiesInStock;
}
public void setCopiesInStock(int copiesInStock) {
this.copiesInStock = copiesInStock;
}
public void updateCopiesInStock(int copiesInStock) {
this.copiesInStock = copiesInStock;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.