Concept explainers
Given main() and a base Book class, define a derived class called Encyclopedia with member methods to get and set private fields of the following types:
- String to store the edition
- int to store the number of pages
Within the derived Encyclopedia class, define a printInfo() method that overrides the Book class' printInfo() method by printing the title, author, publisher, publication date, edition, and number of pages.
Ex. If the input is:
The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe Ian Ridpath Watson-Guptill 2001 2nd 384
the output is:
Book Information: Book Title: The Hobbit Author: J. R. R. Tolkien Publisher: George Allen & Unwin Publication Date: 21 September 1937 Book Information: Book Title: The Illustrated Encyclopedia of the Universe Author: Ian Ridpath Publisher: Watson-Guptill Publication Date: 2001 Edition: 2nd Number of Pages: 384
BookInformation.java
import java.util.Scanner;
public class BookInformation {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
Book myBook = new Book();
Encyclopedia myEncyclopedia = new Encyclopedia();
String title, author, publisher, publicationDate;
String eTitle, eAuthor, ePublisher, ePublicationDate, edition;
int numPages;
title = scnr.nextLine();
author = scnr.nextLine();
publisher = scnr.nextLine();
publicationDate = scnr.nextLine();
eTitle = scnr.nextLine();
eAuthor = scnr.nextLine();
ePublisher = scnr.nextLine();
ePublicationDate = scnr.nextLine();
edition = scnr.nextLine();
numPages = scnr.nextInt();
myBook.setTitle(title);
myBook.setAuthor(author);
myBook.setPublisher(publisher);
myBook.setPublicationDate(publicationDate);
myBook.printInfo();
myEncyclopedia.setTitle(eTitle);
myEncyclopedia.setAuthor(eAuthor);
myEncyclopedia.setPublisher(ePublisher);
myEncyclopedia.setPublicationDate(ePublicationDate);
myEncyclopedia.setEdition(edition);
myEncyclopedia.setNumPages(numPages);
myEncyclopedia.printInfo();
}
}
Book.java
public class Book {
protected String title;
protected String author;
protected String publisher;
protected String publicationDate;
public void setTitle(String userTitle) {
title = userTitle;
}
public String getTitle() {
return title;
}
public void setAuthor(String userAuthor) {
author = userAuthor;
}
public String getAuthor(){
return author;
}
public void setPublisher(String userPublisher) {
publisher = userPublisher;
}
public String getPublisher() {
return publisher;
}
public void setPublicationDate(String userPublicationDate) {
publicationDate = userPublicationDate;
}
public String getPublicationDate() {
return publicationDate;
}
public void printInfo() {
System.out.println("Book Information: ");
System.out.println(" Book Title: " + title);
System.out.println(" Author: " + author);
System.out.println(" Publisher: " + publisher);
System.out.println(" Publication Date: " + publicationDate);
}
}
Encyclopedia.java
public class Encyclopedia extends Book {
// TODO: Declare private fields
// TODO: Define mutator methods -
// setEdition(), setNumPages()
// TODO: Define accessor methods -
// getEdition(), getNumPages()
// TODO: Define a printInfo() method that overrides
// the printInfo in Book class
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps
can i just get the code
can i just get the code
- 2. Student (extend the class Person) that has the following: Data Fields: private int ID prvate double grade Constructor: Constructor to create a Student object with specifiedname address, ID & grade. Methods: Accessor and mutator methods for all data fields.arrow_forward6. Patient Charges Write a class named Patient that has attributes for the following data: • First name, middle name, and last name • Address, city, state, and ZIP code • Phone number ● The Patient class's init__ method should accept an argument for each attribute. The Name and phone number of emergency contact Patient class should also have accessor and mutator methods for each attribute. Next, write a class named Procedure that represents a medical procedure that has been performed on a patient. The Procedure class should have attributes for the following data: • Name of the procedure • Date of the procedure • Name of the practitioner who performed the procedure • Charges for the procedure 107 The Procedure class's __init__ method should accept an argument for each attribute. The Procedure class should also have accessor and mutator methods for each attribute Next, write a program that creates an instance of the Patient class, initialized with sample data. Then, create three…arrow_forwardCode the StudentAccount class according to the class diagramMethods explanation:pay(double): doubleThis method is called when a student pays an amount towards outstanding fees. The balance isreduced by the amount received. The updated balance is returned by the method.addFees(double): doubleThis method is called to increase the balance by the amount received as a parameter. The updatedbalance is returned by the method.refund(): voidThis method is called when any monies owned to the student is paid out. This method can onlyrefund a student if the balance is negative. It displays the amount to be refunded and set thebalance to zero. (Use Math.abs(double) in your output message). If there is no refund, display anappropriate message.Test your StudentAccount class by creating objects and calling the methods addFees(), pay() andrefund(). Use toString() to display the object’s data after each method calledarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education