Question

In: Computer Science

in JAVA please Some of the characteristics of a book are the title, authors, publisher, ISBN,...

in JAVA please

Some of the characteristics of a book are the title, authors, publisher, ISBN, price, and year of publication. Design the class Book so that each object can hold the following information about a book: title, up to four authors, publisher, ISBN, price, and number of copies in stock. To keep track the number of authors, you can add a variable; Including the methods to perform various operations on the 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 an actual title of the book. In the similar way, 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. Write the definitions of the methods of the class Book based on the instruction in a). Write a program that uses the class Book and test various operations on the objects of class Book. Say declare an array of 100 components of the type book. Some 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.

Solutions

Expert Solution

/***********************************Book.java*********************/

package books;

import java.util.ArrayList;

/**
* The Class Book.
*/
public class Book {

   /** The title. */
   private String title;

   /** The authors. */
   private ArrayList<String> authors;

   /** The publisher. */
   private String publisher;

   /** The isbn. */
   private String isbn;

   /** The price. */
   private double price;

   /** The number of copies in stock. */
   private int numberOfCopiesInStock;

   /**
   * Instantiates a new book.
   */
   public Book() {
       super();
       this.title = "";
       this.authors = new ArrayList<>();
       this.publisher = "";
       this.price = 0;
       this.isbn = "";
       this.numberOfCopiesInStock = 0;
   }

   /**
   * Instantiates a new book.
   *
   * @param title the title
   * @param authors the authors
   * @param isbn the isbn
   * @param price the price
   */
   public Book(String title, ArrayList<String> authors, String isbn, double price) {
       super();
       this.title = title;
       this.authors = authors;
       this.isbn = isbn;
       this.price = price;
   }

   /**
   * Gets the title.
   *
   * @return the title
   */
   public String getTitle() {
       return title;
   }

   /**
   * Sets the title.
   *
   * @param title the new title
   */
   public void setTitle(String title) {
       this.title = title;
   }

   /**
   * Gets the authors.
   *
   * @return the authors
   */
   public ArrayList<String> getAuthors() {
       return authors;
   }

   /**
   * Sets the authors.
   *
   * @param authors the new authors
   */
   public void setAuthors(ArrayList<String> authors) {
       this.authors = authors;
   }

   /**
   * Gets the publisher.
   *
   * @return the publisher
   */
   public String getPublisher() {
       return publisher;
   }

   /**
   * Sets the publisher.
   *
   * @param publisher the new publisher
   */
   public void setPublisher(String publisher) {
       this.publisher = publisher;
   }

   /**
   * Gets the isbn.
   *
   * @return the isbn
   */
   public String getIsbn() {
       return isbn;
   }

   /**
   * Sets the isbn.
   *
   * @param isbn the new isbn
   */
   public void setIsbn(String isbn) {
       this.isbn = isbn;
   }

   /**
   * Gets the price.
   *
   * @return the price
   */
   public double getPrice() {
       return price;
   }

   /**
   * Sets the price.
   *
   * @param price the new price
   */
   public void setPrice(double price) {
       this.price = price;
   }

   /**
   * Gets the number of copies in stock.
   *
   * @return the number of copies in stock
   */
   public int getNumberOfCopiesInStock() {
       return numberOfCopiesInStock;
   }

   /**
   * Sets the number of copies in stock.
   *
   * @param numberOfCopiesInStock the new number of copies in stock
   */
   public void setNumberOfCopiesInStock(int numberOfCopiesInStock) {
       this.numberOfCopiesInStock = numberOfCopiesInStock;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Book [title=" + title + ", authors=" + authors + ", publisher=" + publisher + ", isbn=" + isbn
               + ", price=" + price + ", numberOfCopiesInStock=" + numberOfCopiesInStock + "]";
   }

}
/*********************TestBook.java********************/

package books;

import java.util.ArrayList;


/**
* The Class TestBook.
*/
public class TestBook {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {

       Book[] books = new Book[100];

       ArrayList<String> authors = new ArrayList<>();
       authors.add("James Gosling");
       books[0] = new Book("Intro to Java", authors, "2134-32-3233", 150);
       books[1] = new Book("Intro To C++", authors, "343-545-4545", 120);
       books[0].setNumberOfCopiesInStock(20);
       books[1].setNumberOfCopiesInStock(10);
       searchByTitle(books, "Intro to Java");
       searchByISBN(books, "343-545-4545");

   }

   /**
   * Search by ISBN.
   *
   * @param books the books
   * @param string the string
   */
   private static void searchByISBN(Book[] books, String string) {
       try {
           for (Book book : books) {

               if (book.getIsbn().equalsIgnoreCase(string)) {

                   System.out.println(book.toString());
               }

           }
       } catch (Exception e) {

       }

   }

   /**
   * Search by title.
   *
   * @param books the books
   * @param string the string
   */
   private static void searchByTitle(Book[] books, String string) {

       try {
           for (Book book : books) {

               if (book.getTitle().equalsIgnoreCase(string)) {

                   System.out.println(book.toString());
               }

           }
       } catch (Exception e) {

       }
   }
}
/******************output******************/

Book [title=Intro to Java, authors=[James Gosling], publisher=null, isbn=2134-32-3233, price=150.0, numberOfCopiesInStock=20]
Book [title=Intro To C++, authors=[James Gosling], publisher=null, isbn=343-545-4545, price=120.0, numberOfCopiesInStock=10]

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition,...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition, price), PK: ISBN, FK: published_by refs Publisher, previous_edition refs Book. Author (SSN, first_name, last_name, address, income), PK: SSN. Write (aSSN, bISBN), PK: (aSSN, bISBN), FK: aSSN refs Author, bISBN refs Book. Editor (SSN, first_name, last_name, address, salary, works_for, book_count), PK: SSN, FK: works_for refs Publisher. Edit (eSSN, bISBN), PK: (eSSN, bISBN), FK: eSSN refs Editor, bISBN refs Book. Author_Editor (aeSSN, hours), PK: aeSSN, FK:...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition,...
Consider the following schema: Publisher (name, phone, city), PK: name. Book (ISBN, title, year, published_by, previous_edition, price), PK: ISBN, FK: published_by refs Publisher, previous_edition refs Book. Author (SSN, first_name, last_name, address, income), PK: SSN. Write (aSSN, bISBN), PK: (aSSN, bISBN), FK: aSSN refs Author, bISBN refs Book. Editor (SSN, first_name, last_name, address, salary, works_for, book_count), PK: SSN, FK: works_for refs Publisher. Edit (eSSN, bISBN), PK: (eSSN, bISBN), FK: eSSN refs Editor, bISBN refs Book. Author_Editor (aeSSN, hours), PK: aeSSN, FK:...
The most common attributes of a book are the Book Title, and ISBN. The most common...
The most common attributes of a book are the Book Title, and ISBN. The most common functions are to set the Book Title, and ISBN, Write the code to implement this problem. 1. Write the UML Diagram that represents this class Book 2. Use code blocks editor and in C++ Write a header file Book with these properties. Write the implementation file for the member functions.
Add the following private attributes: String publisher String title String ISBN String imageName double price Create...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create getter/setter methods for all data types Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the book object that is formatted nicely and contains all information (attributes) In the main class: Create a main method that throws FileNotFoundException Import java.io libraries Import java.util.Scanner Create a loop to read...
Write an ISBN Validator in C language What are ISBN? ISBN, or International Standard Book Number,...
Write an ISBN Validator in C language What are ISBN? ISBN, or International Standard Book Number, is a numeric identifier for commercially printed books. Prior to 2007, they had 10 digits, but all newly issued ISBN use 13 digits. They are used to uniquely identify a book and consist of several portions. These include the registrant group, publisher, title, and a check digit. The registrant group indicates where the publisher is located. For example a registrant group of 0 or...
Using textbook Title Introductory Financial Accounting for Business Author Edmonds, Christopher T. ISBN 978-1-260-81444-6 Publisher McGraw-Hill...
Using textbook Title Introductory Financial Accounting for Business Author Edmonds, Christopher T. ISBN 978-1-260-81444-6 Publisher McGraw-Hill Education Publication Date January According to GAAP, uncollectible receivables must be estimated and recorded as an expense in the period in which the corresponding revenue is earned. This ensures compliance with the matching principle. (1) Compare and contrast the percent of revenue method and the percent of receivables method. (2) Why would a financial manager or analyst be concerned if the Allowance for Doubtful...
Teen Book Review: The grieving teen: A guide for teenagers and their frends. ISBN: 0684868040 ISBN-13:...
Teen Book Review: The grieving teen: A guide for teenagers and their frends. ISBN: 0684868040 ISBN-13: 9780684868042 Authors:Helen FitzGerald THE FOLLOWING QUESTIONS ARE NOT CONTENT FROM THE BOOK BUT THOUGHTS FROM THE BOOK Recently many publishers have responded to the need for books that are designed to help adults discuss a difficult topic, death, with young children, and/or teens. You are to select one book (many are on Amazon), written for teens, and evaluate it based on what we have...
A book publisher is planning to produce a book in three different bindings: paperback, book club...
A book publisher is planning to produce a book in three different bindings: paperback, book club and library. A paperback takes 2 minutes to sew, 4 minutes to glue, and sells for a profit of 25 cents. A book club edition takes 2 minutes to sew, 6 minutes to glue, and sells for a profit of 40 cents. A library edition takes 3 minutes to sew, 10 minutes to glue, and sells for a profit of 60 cents. The sewing...
C#: A book publisher has limited the cost of every book they publish to no more...
C#: A book publisher has limited the cost of every book they publish to no more than 10 cents per page. Create a BookException class with a constructor that requires three (3) arguments for each book: a string title, a double price and an int number of pages. Create an error message that is passed to the Exception class constructor for the Message property when a book does not meet the price-to-pages ratio. The error message might be:                                                                      For...
CIS- Python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10....
CIS- Python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. The last digit, d10, is a checksum, which is calculated from the other nine digits using the following formula: (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11 If the checksum is 10, the last digit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT