Fraction Class Design Implement the following class design. Make sure to use imp
ID: 3854581 • Letter: F
Question
Fraction Class Design Implement the following class design. Make sure to use implement the methods to have the same names as given below, with the same number and types of parameters. public class Fraction private int numer; private int denomi alternate constructor public Fraction (int numer, int denom) throws li Denominator ception. copy constructor public Fraction (Fraction other Frac) getters public int getNumer public int get Denom. standard methods public String to String public boolean equals (Fraction r FracExplanation / Answer
/** * @author * @fileName Fraction.java * @since 3/3/17 */ public class Fraction { private int numer; private int denom; /** * FULL CONSTRUCTOR - an arg for each class data member * * @param numer * @param denom */ public Fraction(int numer, int denom) throws InvalidDenominatorException { if (denom == 0) { throw new InvalidDenominatorException(); } else { if (denom < 0) { int gcd = GCD(numer, denom); this.numer = (int) (((denom > 0) ? 1 : -1) * numer / gcd) * (-1); this.denom = (int) (Math.abs(denom) / gcd) * (-1); } else { int gcd = GCD(numer, denom); this.numer = (int) (((denom > 0) ? 1 : -1) * numer / gcd); this.denom = (int) (Math.abs(denom) / gcd); } } reduce(); } /** * COPY CONSTRUCTOR - takes ref to some already initialized Fraction object * * @param other */ public Fraction(Fraction other) { this(other.numer, other.denom); // call my full C'Tor with other } // ACCESSORS public int getNumer() { return numer; } public int getDenom() { return denom; } public String toString() { return " " + numer + "/" + denom; } public Fraction add(Fraction b) { return new Fraction(this.numer * b.denom + b.numer * this.denom, this.denom * b.denom); } public double convertToDecimal() { // implement this method! // return double floating point value return (double) this.numer / this.denom; } // end toDouble public Fraction sub(Fraction b) { return add(new Fraction(-b.numer, b.denom)); } public Fraction mult(Fraction b) { return new Fraction(numer * b.numer, denom * b.denom); } public Fraction div(Fraction b) { return new Fraction(numer * b.denom, b.numer * denom); } /** * This method return true if fraction is a proper fraction * if numerator numer) { for (int i = 1; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.