Answered step by step
Verified Expert Solution
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:
- Attributes for the Book'stitle(String),numOfPages(int),pubYear(int),genre(String),author(String) and auniquebookID(int).
- A default constructor which should set default values for all attributes and sets the unique value for thebookID.
- A general constructor which takes in values for all the class attributes except the uniquebookIDand sets them accordingly.
- Provide getter methods for thetitle,authorandbookIDof aBook.
- Provide a setter method for thegenreof aBook.
- 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:
- Declare an array of 5 Book objects.
- Instantiate eachBookobject by obtaining the necessary attribute values from user input.
- Use the appropriate getter methods to print thetitle,authorandbookIDof the thirdBookin the array.
- TheBookin the second position must be reclassified as a "Fantasy" book. Implement this change in code.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started