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

Book Class: represents a book and can be online, digital, or hardcopy. Books hav

ID: 3781999 • Letter: B

Question

Book Class: represents a book and can be online, digital, or hardcopy. Books have a title, author, number of pages, and a publication year (or year of last revision if online). Required items (beyond the basics to set up a properly structured class): A constructor that takes input of title, author, publication year, number of pages, as two Strings and two ints A getPages method that returns the number of pages in the book at this time. A tostring() method that returns a String suitable for printing out the key information about the book. You decide the format but it should all be one line when the string is printed. Be sure to include the number of pages in the book in the returned string. An updateBook method that works with the existing book object to change its publication year and number of pages. Get the new values for publication year and pages as parameters.

Explanation / Answer

HI Friend, Please find my implementation.

Please let me know in case of any issue.

public class Book {

  

   // instance variable

   private String title;

   private String author;

   private int publicationYear;

   private int numberOfPages;

  

   // constructor

   public Book(String title, String author, int publicationYear, int numberOfPages) {

       super();

       this.title = title;

       this.author = author;

       this.publicationYear = publicationYear;

       this.numberOfPages = numberOfPages;

   }

  

   public int getPages(){

       return numberOfPages;

   }

  

   @Override

   public String toString() {

       return "Title: "+title+", Author: "+author+", Pages: "+numberOfPages+

               "Publication Year: "+publicationYear;

   }

  

   public void updateBook(int publicationYear, int pages){

       this.publicationYear = publicationYear;

       numberOfPages = pages;

   }

}