Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. In the Book.java file define a class named Book as follows: a. Declare the following fields. Be sure to choose appropriate names and data

image text in transcribedimage text in transcribedimage text in transcribed

1. In the Book.java file define a class named Book as follows: a. Declare the following fields. Be sure to choose appropriate names and data types for each field. i. an instance variable to store the title of the book ii. an instance variable to store the author of the book iii. an instance variable to hold the number of pages in the book iv. an instance variable that holds a true/false value representing whether the book has a hardback cover or not V. an instance variable that holds the cover price as a decimal b. Declare a default constructor that initializes a book with the following attributes: i. The title is Untitled ii. The author is Unknown iii. The number of pages is 100 iv. The book is not hardback v. The cover price is $4.99 c. Declare a constructor that takes parameters for title, author, pages, hardback and cover price. Initialize the instance variables to the values passed in to the parameters. d. Write a getter and setter for each instance variable. e. Write a toString method that returns a String that describes the Book like this: A Tale Of Two Cities, by Charles Dickens (489 pages, paperback, $3.95) f. Write a method named pricePerPage that returns the price per page of the book. 2. Define a class in MyProgram.java that has a main method that does the following: a. Create a Book using the default constructor. b. Create a local variable named bookInfo and store the result a of calling toString() on the default book. c. print bookInfo. d. Set the title and author of the default book to "The Spare Detective" by "Justin Case". e. update bookInfo by calling toString() and print it again. f. Set the price of the default book to $8.75 g. print out a message announcing the price change, using getters for the attributes as appropriate to output a message like this: The Spare Detective, by Justin Case, now costs $8.75 h. Call pricePerPage() on the default book and store the result in a variable. i. print out the price per page in a message like this: The price per page is $0.0875 j. Create the book The Hobbit by J.R.R. Tolkien, a paperback with 320 pages costing $6.50 using the constructor that takes parameters. k. print the result of calling toString() on the hobbit book. 1. print the price per page of the hobbit book in a message like this: The Hobbit costs $0.0203125 per page 3. prompt the user for the title, author, number of pages, cover price of a book and whether or not it is hardback. a. When asking if the book is hardback interpret answers of yes, affirmative or y (ignore case) as true and everything else as false. If they enter more than one word, only interpret the first word. Hint: Look in this trimmed version of the String API to see how to convert strings to lower or upper case or to ignore case when comparing strings. b. Create a book using the values the user entered c. Print the result of calling toString() on that book. The program output should be (user input can vary): Untitled, by Unknown (100 pages, paperback, $4.99) The Spare Detective, by Justin Case (100 pages, paperback, $4.99) The Spare Detective, by Justin Case, now costs $8.75 The price per page is $0.0875 The Hobbit, by J.R.R. Tolkien (320 pages, paperback, $6.5) The Hobbit costs $0.0203125 per page Enter a title: A Game of Thrones Enter the Author : George R.R. Martin Enter the number of pages: 864 Enter the cover price: 11.67 Is the book hardback? No A Game of Thrones, by George R.R. Martin (864 pages, paperb ack, $11.67)

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

Design a training session to maximize learning. page 296

Answered: 1 week ago

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago