Question: Write a Java program that inputs data from a file and outputs to the screen. A base class called Book defines the name and number

Write a Java program that inputs data from a file and outputs to the screen. A base class called Book defines the name and number of pages in a book. An integer called code is set to 0 for novels, 1 for nonfiction. Fiction and Nonfiction derive from book. Fiction contains a string field describing the genre of the novel. Nonfiction has two fields: subject and num_illustrations. The data file contains (books.dat)

0 Thunderball 245 Spy

0 Goldeneye 289 Spy

1 Airplanes 456 Aviation 250

0 Jocularity 198 Humor

1 Football 434 Sports 400

1 Golf 432 Sports 307

producing this output:

Name:Thunderball Pages:245 Genre:Spy

Name:Goldeneye Pages:289 Genre:Spy

Name:Airplanes Pages:456 Subject:Aviation Illustrations:250

Name:Jocularity Pages:198 Genre:Humor

Name:Football Pages:434 Subject:Sports Illustrations:400

Name:Golf Pages:432 Subject:Sports Illustrations:307

Total pages:2054

In main, an array of references to class book called books is used to store all objects of either fiction or nonfiction. Use polymorphic functions to read and print the data. A count of the total number of pages of all books in the data is maintained by class book. (Hint: static data and method) Read all the data and make all the objects before printing the output. Print in a separate loop after completing reading.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!