Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in java define a fraction class containing a numerator and a denominator -access

ID: 3640620 • Letter: I

Question

in java define a fraction class containing a numerator and a denominator
-accessors and mutators
-define an equals method to determine if 2 fractions are equivalent
-also define methods for adding,subtracting,multiplying, or dividing fractions, all of which should return a fraction
Then write a main method in a separate class which exercises this functionality, perhaps interactively
Please be descriptive of how you came up with this

Explanation / Answer

PS: Please rate the answer Save as Fraction.java public class Fraction { private int num; //numerator private int den; //denominator public Fraction(int n, int d) // constructor that requires 2 digits of input { // assign num = n & den = d as long as d!= 0 if(d != 0) { num = n; den = d; } else System.exit(0); } private static int gcd(int x, int y) { /* gcd() method finds the greatest common divisor of * the 2 int variables passed and returns that value * */ int mod; // hold a value temporarily to allow switch if(x den && den > 1) //if true will show fraction object and mixed number return (num + "/" + den + " or " + (num/den) + " " + (num % den) + "/" + den); else return(num + "/" + den); //will not try to convert fraction object to mixed number } public static void main(String args[]){ Fraction newFraction1 = new Fraction(2,3); Fraction newFraction2 = new Fraction(3,2); Fraction newFraction3 = newFraction1.add(newFraction2); System.out.println(newFraction3.toString()); } }