Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a BookException class with a constructor that requires three (3) argument

ID: 3627414 • Letter: C

Question

Create a BookException class with a constructor that requires three (3) arguments for each book: a string title, a double price and an int number of pages.

Create an error message that is passed to the Exception class constructor for the Message property when a book does not meet the price-to-pages ratio. The error message might be:

For Goodnight Moon, ratio is invalid.

...Price is $12.99 for 25 pages

The price-to-pages ratio is determined by checking the following: price > RATE * pages where RATE = 0.10

Create a Book class that has the following fields: string title, string author, double price and int number of pages.

Create properties (accessors) for each field.

Throw a BookException if a book object is created that has a price that is more than 10 cents per page.

In Main create 4 Book objects and use the constructor for Book to pass the four inputs when each object is instantiated, some where the ratio is correct and some where the ratio is not correct.

Catch any thrown exceptions and display BookException Message.

Internal Documentation.


Possible output for 6a:

The inputs passed were:

("Goodnight Moon", "Brown", 12.99, 25)

("World History", "Stein", 72.99, 900)

("The Grapes of Math", "Stoltz", 30.99, 300)

("Steal This Book", "Hoffman", 72.99, 800)

The results were:

For Goodnight Moon, ratio is invalid.
...Price is $12.99 for 25 pages.
For The Grapes of Math, ratio is invalid.
...Price is $30.99 for 300 pages.
Press any key to continue . . .

Explanation / Answer

catch(e)
{
System.out.println(t+","+"ratio is invalid");
System.out.println("price is"+p+"for"+pg);
}

class Book
{
string title;
String author;
double price;
int nopages;
//setter methods
public void setTitle(String tname)
{
title=tname;
}
public void setAuthor(String authorname)
{
author=authorname;
}
public void setPrice(double p)
{
price=p;
}
public void setPages(int page)
{
nopages=page;
}