Catch any thrown exceptions and display bookexception messag

Assignment Help Programming Languages
Reference no: EM13936060

A book publisher has limited the cost of every book they publish to no more than 10 cents per page.

[A] Create a BookException class (in C-Sharp) 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 like:

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. Throw a BookException if a book object is created that has a price that is more than 10 cents per page.

For testing, 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.

For example, if 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 possible output could be:

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 . . .

[B] Using the Book class created above, create an application that creates an array of five Book objects, and prompt the user for input values for each Book instead of setting the values with constructors.

To handle any exceptions that are thrown because of improper or invalid data entered by the user, set the Book's price to a maximum 10 cents per page.

At the end of the program display all the entered, and possibly corrected, records.

Possible inputs/output could look like:

Enter title Book 1

Enter author Author 1

Enter price 33.33

Enter pages 333

For Book 1, ratio is invalid.

...Price is $33.33 for 333 pages.

Enter title Book 2

Enter author Author 2

Enter price 22.22

Enter pages 333

Enter title Book 3

Enter author Author 3

Enter price 45.00

Enter pages 200

For Book 3, ratio is invalid.

...Price is $45.00 for 200 pages.

Enter title Book 4

Enter author Author 4

Enter price 25.00

Enter pages 1000

Enter title Book 5

Enter author Author 5

Enter price 30.00

Enter pages 850

Book 1 by Author 1 Price $33.30 333 pages.

Book 2 by Author 2 Price $22.22 333 pages.

Book 3 by Author 3 Price $20.00 200 pages.

Book 4 by Author 4 Price $25.00 1000 pages.

Book 5 by Author 5 Price $30.00 850 pages.

Press any key to continue . . .

Other possible errors might be entered as shown below:

Enter title Book 1

Enter author Author 1

Enter price 33.xx

Input string was not in a correct format.

Enter title Book 1

Enter author Author 1

Enter price 33.33

Enter pages xx.33

Input string was not in a correct format.

Enter title ...

Reference no: EM13936060

Questions Cloud

Do you think raven ltd should hedge its remittance : Based on this information, do you think Raven Ltd should hedge its remittance of expected Japanese yen profits to the UK parent by selling yen forward contracts? Why would this strategy be advantageous?
Define and discuss key terms associated with the event : You are to select ONE healthcare reimbursement event and discuss the following: History and purpose and Define and discuss key terms associated with the event
What will be probability distribution of the yens change : If Stillwater Ltd uses this information to forecast the Japanese yen's exchange rate, what will be the probability distribution of the yen's percentage change over the upcoming period?
Unpredictable and ever flexible business environment : "In today's highly volatile, unpredictable and ever flexible business environment, organisations can only take an emergent approach to change."
Catch any thrown exceptions and display bookexception messag : A book publisher has limited the cost of every book they publish to no more than 10 cents per page.
Process to get merchandize to your customers : • Some process to get merchandize to your customers. To spice things up a bit you have decided to sell something funny and demanding like: • T-shirts with a Superhero image and your company logo on them.
Discuss the necessity of rulemaking : Discuss the necessity of Rulemaking and the role that interest groups play in it
Triarchic theory of intelligence : The Triarchic Theory of Intelligence describes three kinds of intelligence: Analytical, Practical and Creative. Explain the essence of this theory and give examples of each (from your memory or imagination not the textbook) of these types of intel..
Determine whether there is a forecast bias in forward rate : You must determine whether there is a forecast bias in the forward rate. You apply regression analysis to test the relationship between the actual spot rate and the forward rate forecast (F).

Reviews

Write a Review

Programming Languages Questions & Answers

  Draw and implement class which contains instance data

Draw and Implement the class called "Box" which contains instance data (all doubles) that represents height, width, and depth of the box. Also include boolean variable called "full" as instance.

  List various bindings to determine the semantics

List the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

  Design program that asks user to enter budgeted amount

"Design a program that asks the user to enter the amount that he or she has budgeted for a month. (For example: $2,000.00)

  Provide a brief description within comment tags at bottom

Provide a brief description within comment tags at the bottom

  Write a subroutine named as count_monomers

In a similar way, write a subroutine named as "count_codons" to count and print the frequency of each codon, sorted by codons. Your codon counts should be the same as those produced by the listed code.

  Write program which will ask user to enter last names

Write a program which will ask the user to enter last names of our candidates in class officer's president election and number of votes received each candidate.

  Html5 assignment i need an assignment for html5 containing

i need an assignment for html5 containing 2 parts1 3 pages html5 website2 report more important than the website

  Write program that merges two files

The first programming project involves writing a program that merges two files that contain polynomials. To merge two files, the input files must be in sorted order.

  Write program which comprises function to compute calories

Write down program which comprises function calories() that is to accept long integer number total and address of integer variables pizza, chips apples and mustard.

  Create the object-oriented design for dvd collection

Create the object-oriented design for system which keeps tracks of your CD and DVD collection. Recognize each of the classes, associated data, and operations for classes.

  Calculate interest on account balance-get total amount due

Accepts account balance and calculates interest on Account balance. It then adds on interest to get total amount due.

  Create a rexx program

Create a REXX program that asks a user for four separate lines of input, and then outputs those lines all at once, one line at a time

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd