Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi there! Can you help me with this java program. Part A: Have a class to represent a Book . This should include the following:

Hi there!

Can you help me with this java program.

Part A:

Have a class to represent aBook. This should include the following:

  1. Attributes for the Book'stitle(String),numOfPages(int),pubYear(int),genre(String),author(String) and auniquebookID(int).
  2. A default constructor which should set default values for all attributes and sets the unique value for thebookID.
  3. A general constructor which takes in values for all the class attributes except the uniquebookIDand sets them accordingly.
  4. Provide getter methods for thetitle,authorandbookIDof aBook.
  5. Provide a setter method for thegenreof aBook.
  6. Provide aprintBookDetailsmethod that prints all the details of aBook.Note:Please check expected output below.

Part B:

Have a main method in a new class calledBookDataBaseand in this method:

  1. Declare an array of 5 Book objects.
  2. Instantiate eachBookobject by obtaining the necessary attribute values from user input.
  3. Use the appropriate getter methods to print thetitle,authorandbookIDof the thirdBookin the array.
  4. TheBookin the second position must be reclassified as a "Fantasy" book. Implement this change in code.
  5. Call theprintBookDetailsmethod to print the attributes for eachBookobject.

Input

Shown below is the input order for oneBookobject.

Important Note:When using User Input to take in an integer for this question, please useInteger.parseInt(sc.nextLine())Please see example usage below.

 Scanner sc = new Scanner(System.in); int num = Integer.parseInt(sc.nextLine()); 

Input for 1 Book

 title (String) numOfPages (int) pubYear (int) genre (String) author (String) 

Sample Input for 1 Book

 Fly Fishing 128 1938 Sport J. R. Hartley 

Sample Output- output should be exactly as below:

 The third book is And Then There Were None It was written by Agatha Christie and has an ID of 3 Book Details Title: The Little Prince Pages: 120 Publish Year: 1943 Genre: fantasy Author: Antoine de Saint-Exupery ID: 1 Book Details Title: The Lord of the Rings Pages: 900 Publish Year: 1954 Genre: Fantasy Author: J. R. R. Tolkien ID: 2 Book Details Title: And Then There Were None Pages: 153 Publish Year: 1939 Genre: mystery Author: Agatha Christie ID: 3 Book Details Title: Dream of the Red Chamber Pages: 253 Publish Year: 1791 Genre: family Author: Cao Xueqin ID: 4 Book Details Title: The Master and Margarita Pages: 178 Publish Year: 1967 Genre: supernatural Author: Mikhail Bulgakov ID: 5 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions