Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this Java Programming assignment: Two files are required, a data class named Book and an executable class named BookTest . Book

I need help with this Java Programming assignment:

Two files are required, a data class named Book and an executable class named BookTest.

Book

Class Book (a data class, no main method)

five instance data members, all private:

String title, String isbn, String author, double price, int pages.

one public static, or class, member named numBooks assigned an initial value of zero.

a no-arg constructor, and another parameterized constructor that sets values in all data members when called. Both constructors should increment the numBooks static data member.

has setters and getters for all data members.

a toString() method that returns the state of all data members of a Book instance

BookTest

Class BookTest

defines a void method named reduceBooks that takes a Book object and a double as its only parameters. The method reduces the price of the Book passed to it by the double amount.

In main:

create an ArrayList of type Book.

add four or five Book instances to the list using the parameterized constructor. Be sure to make 973 the first three numbers in the ISBN of several books. This will be used later.

create another Book instance with the no-arg constructor. Assume this is our course textbook.

use the Book class setter methods to assign values to this Book's data members.

add this book to the list at index 2.

use a foreach loop to process the arraylist and locate Books whose ISBN starts with 973. Call the reduceBooks method for these books and reduce their prices by $5.00.

print the static numBooks member to report the number of books displayed.

use another foreach loop to display all books in the list, but total up their prices as you do so.

report the total price of all books.

Example Output

Some good books...

Title=Redemption Road, isbn=973-1250132116, author=John Hart, price=14.34, pages=464

Title=Wounds, isbn=973-0008189259, author=Fergal Keane, price=9.93, pages=368

Title=Intro to Java Programming, isbn=978-0134670942, author=Daniel Liang, price=151.51, pages=1232

Title=No Exit, isbn=978-1912106943, author=Taylor Adams, price=17.99, pages=285

Title=Camino Island, isbn=973-0385543026, author=John Grisham, price=14.79, pages=304

Title=Beneath a Scarlet Sky, isbn=978-1503943377, author=Mark Sullivan, price=18.63, pages=524

There are 6 books on the shelf

Total purchase price, all books, is $227.19

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions