Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If anyone could show how to do the exception controlled loop, it would be much appreciated! Here is Fraction.java, including what I have added: public

image text in transcribed

If anyone could show how to do the exception controlled loop, it would be much appreciated!

Here is Fraction.java, including what I have added:

public class Fraction {

private int numerator; private int denominator;

/** * Constructor with parameter * * @param numerator numerator * @param denominator denominator */ Fraction(int numerator, int denominator) throws DenominatorIsZeroException { this.numerator = numerator; if(denominator == 0) { throw new DenominatorIsZeroException("Denominator is zero"); } this.denominator = denominator; }

/** * Get the numerator. * * @return numerator */ public int getNumerator() { return numerator; }

/** * Set the numerator. * * @param numerator numerator */ public void setNumerator(int numerator) { this.numerator = numerator; }

/** * Get the denominator. * * @return the denominator */ public int getDenominator() { return denominator; }

/** * Set the denominator. * * @param denominator denominator * @throws DenominatorIsZeroException */ public void setDenominator(int denominator) throws DenominatorIsZeroException { if(denominator == 0) { throw new DenominatorIsZeroException("Denominator is Zero"); } this.denominator = denominator; }

/** * Convert the fraction to a mixed number. * * @return The mixed number. */ public String toMixedNumber() {

String ret = ""; int remainder = numerator % denominator;

ret += numerator / denominator; ret += " "; if (remainder != 0) { ret += numerator % denominator; ret += "/"; ret += denominator; }

return ret; }

/** * Override of {@link java.lang.Object#toString} method. */ @Override public String toString() { String ret = Integer.toString(numerator) + "/" + denominator; return ret; } }

Creating a Custom Exception Class. Topics: Custom Exceptions, try catch finally, throw, throws and exception ontrolled loops. 1. Write DenominatorIsZeroException class by adding the appropriate constructors. 2. Modify the provided Fraction.java so that it throws the DenominatorIsZeroException if the denominator is set to zero. You need to see which methods can potentially throw this exception. 3. Create the tester class CustomException Tester.java that tests the new Fraction class, attempts to set the denominator to zero, and catches the DenominatorIsZeroException exception. Try invoking all of the methods of the fractions class. Here is Fraction.java Challenge: 5 Points Extra Credit Write an exeeption controlled loop that keeps prompting the user to reenter in case the user enters a zero denominator and an exception is thrown. Otherwise, display the mixed number form and exit

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

Describe the factors influencing of performance appraisal.

Answered: 1 week ago

Question

What is quality of work life ?

Answered: 1 week ago

Question

What is meant by Career Planning and development ?

Answered: 1 week ago