SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Exception Handling
Exercise:
Programming Projects
Question:4 | ISBN:9780132830317 | Edition: 5

Question

(This is a version of an exercise from Chapter 5.) Programming Project 5.2 from Chapter 5 asked you to create a class named Fraction. This class is used to represent a ratio of two integers. It should include mutator functions that allow the user to set the numerator and the denominator along with a method that displays the fraction on the screen as a ratio (e.g., 5/9). Modify the class so that it throws the exception DenominatorIsZeroException if the denominator is set to zero. Do not forget to account for the constructors! You will have to create the DenominatorIsZeroException class and it should be derived from Exception .

Write a main method that tests the new Fraction class, attempts to set the denominator to zero, and catches the DenominatorIsZeroException exception.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.