Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Some of the characteristics of a book are the title, author(S), publisher, IS

ID: 3890366 • Letter: A

Question

a. Some of the characteristics of a book are the title, author(S), publisher, ISBN, price, and year of publication. Design a class bookType that defines the book as an ADT i. Each object of the class bookType 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 of the number of authors, add another member variable i. Include the member functions to perform the various operations on objects of type bookType 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 same as 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 and a destructor (if one is needed) b. Write the definitions of the member functions of the class bookType c. Write a program that uses the class bookType and tests various operations on the objects of the class bookType. Declare an array of 100 components of type bookType. 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

public class BookType {

   public String title;
   public String authors[];
   public String publisher;
   public String ISBN;
   public double price;
   public int yearOfPublication;
   public int noOfCopiesInStock;
   public int noOfAuthors;
  
   public BookType() {
       authors = new String[4];
       this.noOfAuthors = 0;
   }
  
   public BookType(String title, String publisher, String iSBN,
           double price, int yearOfPublication, int noOfCopiesInStock) {
       this.ISBN = iSBN;
       this.price = price;
       this.title = title;
       this.publisher = publisher;
       this.yearOfPublication = yearOfPublication;
       this.noOfCopiesInStock = noOfCopiesInStock;
       this.authors = new String[4];
       this.noOfAuthors = 0;
   }

   public BookType(String title, String[] authors, String publisher, String iSBN,
           double price, int yearOfPublication, int noOfCopiesInStock, int noOfAuthors) {
       this.ISBN = iSBN;
       this.price = price;
       this.title = title;
       this.authors = authors;
       this.publisher = publisher;
       this.noOfAuthors = noOfAuthors;
       this.yearOfPublication = yearOfPublication;
       this.noOfCopiesInStock = noOfCopiesInStock;
   }

   public void setTitle(String title) {
       this.title = title;
   }
  
   public String getTitle() {
       return this.title;
   }
  
   public void showTitle() {
       System.out.println("Title : " + title);
   }

   public boolean checkTitle(String title) {
       if (this.title.equalsIgnoreCase(title)) {
           return true;
       }
       return false;
   }
  
  
   public void setNoOfCopiesInStock(int noOfCopiesInStock) {
       this.noOfCopiesInStock = noOfCopiesInStock;
   }

   public int getNoOfCopiesInStock() {
       return this.noOfCopiesInStock;
   }
  
   public void displayNoOfCopiesInStock() {
       System.out.println("No of copies in stock are : " + noOfCopiesInStock);
   }
  
   public void addCopiesToStock(int noOfCopies) {
       if (noOfCopies > 0) {
           this.noOfCopiesInStock += noOfCopies;
       }
   }

   public void removeCopiesToStock(int noOfCopies) {
       if (noOfCopies <= noOfCopiesInStock) {
           this.noOfCopiesInStock -= noOfCopies;
       }
   }

  
   public String[] getAuthors() {
       return authors;
   }

   public void addAuthor(String author) {
       if (noOfAuthors >= 4) {
           return;
       }
       this.authors[noOfAuthors++] = author;
   }

   public void setAuthors(String[] authors) {
       if (authors.length > 4) {
           return;
       }
      
       this.noOfAuthors = 0;
       for (int i=0; i<authors.length && noOfAuthors<4; i++) {
           this.authors[noOfAuthors] = authors[i];
           noOfAuthors++;
       }
   }

   public void displayAuthors() {
       System.out.println("Authors are ");
       for (int i=0; i<noOfAuthors; i++) {
           System.out.println(i + ". " + authors[i]);
       }
   }

   public boolean isAnAuthor(String authorName) {
       for (int i=0; i<noOfAuthors; i++) {
           if (authorName.equalsIgnoreCase(authors[i])) {
               return true;
           }
       }
       return false;
   }

  
   public String getPublisher() {
       return publisher;
   }

   public void setPublisher(String publisher) {
       this.publisher = publisher;
   }

   public void displayPublisher() {
       System.out.println("Publisher is " + publisher);
   }
  
   public boolean checkPublisher(String publisher) {
       if (this.publisher.equalsIgnoreCase(publisher)) {
           return true;
       }
       return false;
   }
  
   public String getISBN() {
       return ISBN;
   }

   public void setISBN(String iSBN) {
       this.ISBN = iSBN;
   }

   public void showISBN() {
       System.out.println("ISBN No. is " + ISBN);
   }

   public boolean checkISBN(String isbn) {
       if (this.ISBN.equalsIgnoreCase(isbn)) {
           return true;
       }
       return false;
   }
  
   public double getPrice() {
       return price;
   }

   public void setPrice(double price) {
       this.price = price;
   }

   public void showPrice() {
       System.out.println("Price is " + price);
   }
  
   public int getYearOfPublication() {
       return yearOfPublication;
   }

   public void setYearOfPublication(int yearOfPublication) {
       this.yearOfPublication = yearOfPublication;
   }

   public void displayYearOfPublication() {
       System.out.println("Year Of Publication " + this.yearOfPublication);
   }
  
}

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

NOTE : The above class defines all the required functionalities. I have left the following driver program paritially completed, it is upto you for completion. I cannot define hundered book objects manually, I can only help you out with the assignments as per the rules of the Chegg. You can test the methods of above BookType as you wish, using the below driver program. The question is not asking something specific to be done, it is upto the student to test all the fucntionalities in whatever way he wants.

public class DriverProgram {
  
   public static void main(String args[]) {
      
       BookType[] bookType = new BookType[100];
      
       bookType[0] = new BookType("Harry Potter - 1", "Bloomsbury Publications", "987652B1NS1", 14.5, 2001, 10);
       bookType[0].addAuthor( "JK Rowling");
      
      
       bookType[1] = new BookType("Harry Potter - 2", "Bloomsbury Publications", "187352B1SHSZK", 25.12, 2003, 23);
       bookType[1].addAuthor( "JK Rowling");
      

       bookType[0].showTitle();
       bookType[0].displayPublisher();
       bookType[0].displayAuthors();
       bookType[0].showPrice();
       bookType[0].showISBN();
      
       bookType[1].showTitle();
       bookType[1].displayPublisher();
       bookType[1].displayAuthors();
       bookType[1].showPrice();
       bookType[1].showISBN();

      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote