Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

=+What sanctions are available to employers

Answered: 1 week ago

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago

Question

=+industrial action Under what circumstances can unions strike?

Answered: 1 week ago