In java i have a class calle rational the input i receive is in yellow and the output is supposed to look like what comes after the yello O OConstructor called with n = 0 and d = 0....


In java


i have a class calle rational


the input i receive is in yellow and the output is supposed to look like what comes after the yello


O OConstructor called with n = 0 and d = 0.<br>java.lang.ArithmeticException: Can't divide by 0.<br>Resulting object is null.<br>

Extracted text: O OConstructor called with n = 0 and d = 0. java.lang.ArithmeticException: Can't divide by 0. Resulting object is null.
Each object of Rational represents a rational number with an integer numerator and a nonzero integer denominator.<br>The instance variables of Rational corresponding to the numerator and denominator are int n and int d.<br>Implement the two-parameter Rational constructor:<br>public Rational (int n, int d) { }<br>The constructor should initialize this.n and this.d to the Rational object representing rational number n/d. Make sure to reduce n and d to lowest terms.<br>Also, to normalize the sign, only this.n is allowed to be negative, not this.d. For example, 4/-5 would be represented by -4/5 and -4/-5 would be represented by 4/5.<br>If 0 is passed in for d, then throw an ArithmeticException with the message

Extracted text: Each object of Rational represents a rational number with an integer numerator and a nonzero integer denominator. The instance variables of Rational corresponding to the numerator and denominator are int n and int d. Implement the two-parameter Rational constructor: public Rational (int n, int d) { } The constructor should initialize this.n and this.d to the Rational object representing rational number n/d. Make sure to reduce n and d to lowest terms. Also, to normalize the sign, only this.n is allowed to be negative, not this.d. For example, 4/-5 would be represented by -4/5 and -4/-5 would be represented by 4/5. If 0 is passed in for d, then throw an ArithmeticException with the message "Can't divide by 0." (Don't forget the period at the end.) If O is passed in for n and d is nonzero then the resulting values for this.n and this.d should be 0 and 1 respectively. The gcd method from exercise 304 is available to you. Suppose we want to implement a rational number class called Rational. Each object of Rational represents a rational number with an integer numerator and a nonzero integer denominator. The instance variables of Rational corresponding to the numerator and denominator are int n and int d. Implement the two-parameter Rational constructor: public Rational (int n, int d) { } The constructor should initialize this.n and this.d to the Rational object representing rational number n/d. Make sure to reduce n and d to lowest terms. Also, to normalize the sign, only this.n is allowed to be negative, not this.d. For example, 4/-5 would be represented by -4/5 and -4/-5 would be represented by 4/5. If O is passed in for d, then throw an ArithmeticException with the message "Can't divide by 0." (Don't forget the period at the end.) If 0 is passed in for n and d is nonzero then the resulting values for this.n and this.d should be 0 and 1 respectively. The gcd method from exercise 304 is available to you.
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here