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 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.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images
Getting a syntax error on the last closing brace of BookArray.java