Question: 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

 If anyone could show how to do the exception controlled loop,

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!