Design a class named Author with the following members: A field for the author’s name (a String) A field for the author’s year of birth (an int) One or more constructors and appropriate accessor and mutator methods A toString method that displays the author’s info as: Author: Mary Shelley (1797) Save the file as Author.java. Next, create an abstract class named Book with the following members: A field for the book title (a String) A field for the book author (a reference to an Author object) A field for the book price (a double) A constructor that requires the title and author Get methods for the title, author, and price An abstract method named setPrice A toString method that displays the book’s title, author’s info, and price as: Frankenstein Author: Mary Shelley (1797) Price: $23.95 Save the file as Book.java. Create Fiction and NonFiction child classes of Book. Each must include a setPrice method that sets the price for all Fiction books to $23.95 and for all NonFiction books to $39.95. Write a constructor for each subclass, and include a call to setPrice() within each. Include an appropriate toString method. Save the files as Fiction.java and NonFiction.java. Finally, write an application named BookArray in which you create an ArrayList that holds 10 Books, some Fiction and some NonFiction. Using a for loop, prompt the user for a title, author, and whether the Book is fiction or nonfiction (F or N). Create the appropriate book type and store it in the array. If the user does not select F or N, reprompt the user. In another for loop, display details about all 10 Books. Save the file as BookArray.java.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Design a class named Author with the following members:

  • A field for the author’s name (a String)
  • A field for the author’s year of birth (an int)
  • One or more constructors and appropriate accessor and mutator methods
  • A toString method that displays the author’s info as: Author: Mary Shelley (1797)

Save the file as Author.java.

Next, create an abstract class named Book with the following members:

  • A field for the book title (a String)
  • A field for the book author (a reference to an Author object)
  • A field for the book price (a double)
  • A constructor that requires the title and author
  • Get methods for the title, author, and price
  • An abstract method named setPrice
  • A toString method that displays the book’s title, author’s info, and price as: Frankenstein Author: Mary Shelley (1797) Price: $23.95

Save the file as Book.java.

Create Fiction and NonFiction child classes of Book. Each must include a setPrice method that sets the price for all Fiction books to $23.95 and for all NonFiction books to $39.95. Write a constructor for each subclass, and include a call to setPrice() within each. Include an appropriate toString method. Save the files as Fiction.java and NonFiction.java.

Finally, write an application named BookArray in which you create an ArrayList that holds 10 Books, some Fiction and some NonFiction. Using a for loop, prompt the user for a title, author, and whether the Book is fiction or nonfiction (F or N). Create the appropriate book type and store it in the array. If the user does not select F or N, reprompt the user. In another for loop, display details about all 10 Books. Save the file as BookArray.java.

Design a class named Author with the following members:
▪ A field for the author's name (a String)
. A field for the author's year of birth (an int)
▪ One or more constructors and appropriate accessor and mutator methods
▪ A toString method that displays the author's info as: Author: Mary Shelley (1797)
Save the file as Author.java.
Next, create an abstract class named Book with the following members:
▪ A field for the book title (a String)
▪ A field for the book author (a reference to an Author object)
▪ A field for the book price (a double)
▪ A constructor that requires the title and author
▪ Get methods for the title, author, and price
▪ An abstract method named setPrice
A toString method that displays the book's title, author's info, and price as:
Frankenstein Author: Mary Shelley (1797) Price: $23.95
Save the file as Book.java.
Create Fiction and NonFiction child classes of Book. Each must include a set Price method that sets the price for
all Fiction books to $23.95 and for all Non Fiction books to $39.95. Write a constructor for each subclass, and
include a call to setPrice() within each. Include an appropriate toString method. Save the files as Fiction.java and
NonFiction.java.
Finally, write an application named BookArray in which you create an ArrayList that holds 10 Books, some
Fiction and some NonFiction. Using a for loop, prompt the user for a title, author, and whether the Book is fiction
or nonfiction (F or N). Create the appropriate book type and store it in the array. If the user does not select F or N,
reprompt the user. In another for loop, display details about all 10 Books. Save the file as BookArray.java.
Author
Mary Shelley
Eric Matthes
Aldous Huxley
Title
Frankenstein
Python Crash Course
Brave New World
One Hundred Years Of Solitude
A Farewell To Arms
The Grapes Of Wrath
The C++ Programming Language
Regular Algebra and Finite Machines
Lord Of The Flies
Starting out with Java. Early objects
Gabriel Garcia Marquez
Ernest Hemingway
John Steinbeck
Bjarne Stroustrup
John Horton Conway
William Golding
Tony Gaddis
Birth
1797
1972
1894
1927
1899
1902
1950
1937
1911
1960
Transcribed Image Text:Design a class named Author with the following members: ▪ A field for the author's name (a String) . A field for the author's year of birth (an int) ▪ One or more constructors and appropriate accessor and mutator methods ▪ A toString method that displays the author's info as: Author: Mary Shelley (1797) Save the file as Author.java. Next, create an abstract class named Book with the following members: ▪ A field for the book title (a String) ▪ A field for the book author (a reference to an Author object) ▪ A field for the book price (a double) ▪ A constructor that requires the title and author ▪ Get methods for the title, author, and price ▪ An abstract method named setPrice A toString method that displays the book's title, author's info, and price as: Frankenstein Author: Mary Shelley (1797) Price: $23.95 Save the file as Book.java. Create Fiction and NonFiction child classes of Book. Each must include a set Price method that sets the price for all Fiction books to $23.95 and for all Non Fiction books to $39.95. Write a constructor for each subclass, and include a call to setPrice() within each. Include an appropriate toString method. Save the files as Fiction.java and NonFiction.java. Finally, write an application named BookArray in which you create an ArrayList that holds 10 Books, some Fiction and some NonFiction. Using a for loop, prompt the user for a title, author, and whether the Book is fiction or nonfiction (F or N). Create the appropriate book type and store it in the array. If the user does not select F or N, reprompt the user. In another for loop, display details about all 10 Books. Save the file as BookArray.java. Author Mary Shelley Eric Matthes Aldous Huxley Title Frankenstein Python Crash Course Brave New World One Hundred Years Of Solitude A Farewell To Arms The Grapes Of Wrath The C++ Programming Language Regular Algebra and Finite Machines Lord Of The Flies Starting out with Java. Early objects Gabriel Garcia Marquez Ernest Hemingway John Steinbeck Bjarne Stroustrup John Horton Conway William Golding Tony Gaddis Birth 1797 1972 1894 1927 1899 1902 1950 1937 1911 1960
C:\Users\Java\Desktop\MidTerm>java BookArray
Enter title: Frankenstein
Enter author name: Mary Shelley
Enter year of author's birth: 1797
Is this a [F]iction or [N]onfiction title: F
Enter title: Python Crash Course
Enter author name: Eric Matthes
Enter year of author's birth: 1972
Is this a [F]iction or [N]onfiction title: N
I
Fiction: Frankenstein Author: Mary Shelley (1797) Price: $23.95
NonFiction: Python Crash Course Author: Eric Matthes (1972) Price: $39.95
Fiction: Brave New World Author: Aldous Huxley (1894) Price: $23.95
Fiction: One Hundred Years Of Solitude Author: Gabriel Garcia MMarquez (1927) Price: $23.95
Fiction: A Farewell To Arms Author: Ernest Hemingway (1899) Price: $23.95
Fiction: The Grapes Of Wrath Author: John Steinbeck (1902) Price: $23.95
NonFiction: The C++ Programming Language Author: Bjarne Stroustrup (1950) Price: $39.95
NonFiction: Regular Algebra and Finite Machines Author: John Horton Conway (1937) Price: $39.95
Fiction: Lord Of The Flies Author: William Golding (1911) Price: $23.95
NonFiction: Starting Out with Java. Early objects Author: Tony Gaddis (1960) Price: $39.95
Transcribed Image Text:C:\Users\Java\Desktop\MidTerm>java BookArray Enter title: Frankenstein Enter author name: Mary Shelley Enter year of author's birth: 1797 Is this a [F]iction or [N]onfiction title: F Enter title: Python Crash Course Enter author name: Eric Matthes Enter year of author's birth: 1972 Is this a [F]iction or [N]onfiction title: N I Fiction: Frankenstein Author: Mary Shelley (1797) Price: $23.95 NonFiction: Python Crash Course Author: Eric Matthes (1972) Price: $39.95 Fiction: Brave New World Author: Aldous Huxley (1894) Price: $23.95 Fiction: One Hundred Years Of Solitude Author: Gabriel Garcia MMarquez (1927) Price: $23.95 Fiction: A Farewell To Arms Author: Ernest Hemingway (1899) Price: $23.95 Fiction: The Grapes Of Wrath Author: John Steinbeck (1902) Price: $23.95 NonFiction: The C++ Programming Language Author: Bjarne Stroustrup (1950) Price: $39.95 NonFiction: Regular Algebra and Finite Machines Author: John Horton Conway (1937) Price: $39.95 Fiction: Lord Of The Flies Author: William Golding (1911) Price: $23.95 NonFiction: Starting Out with Java. Early objects Author: Tony Gaddis (1960) Price: $39.95
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Getting a syntax error on the last closing brace of BookArray.java

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education