The Grader is providing its own inputs, independent from your FractionTester file. In this case, the Grader is using 1/2 and 3/5 for each test. This was unclear in the autograder display, and I've updated the display to make this clear. 1/2 + 3/5 should result in 11/10, 1/2 - 3/5 should result in -1/10, and 1/2 * 3/5 should result in 3/10.
The FractionTester.java file is there just for you to personally test your Fraction class. When you click RUN CODE, the FractionTester.java is run, and whatever Fraction objects you create and call methods on and print in the FractionTester file will show up in the run window. When you click CHECK CODE, a separate Grader file runs, which creates Fraction objects from the Fraction class that you have written, and makes sure that your Fraction class and the methods inside work properly.
For your add and subtract methods, you'll need to cross multiply in order to correctly add and subtract.
a c a*d + c*b
----- + ----- = ------------
b d b*d
So in Java,
add(Fraction other) would look like:
numerator = numerator * other.getDenominator() + other.getNumerator() * denominator;
// a * d + c * b
// I'll let you figure out the code for denominator
Fraction other is simply the name of the parameter passed in to the add method. You can name it whatever you like, other is not particularly significant. The idea is that we want objects of the Fraction class to have certain behavior. A Fraction object should be able to produce a String version of itself (this is what the
toString() method is for), a Fraction object should be able to give out the value of its numerator (this is what the
getNumerator() method is for), and a Fraction object should be able to take a different Fraction object (call it other, otherFraction, fractionToAdd, the name doesn't matter) and add / subtract / multiply this different Fraction object into itself. When we write the add, subtract, and multiply methods, they need to take a parameter to know what the other Fraction is that it is being added, subtracted, or multiplied by.
When you call the add method, and pass in a Fraction as a parameter, the parameter
other takes on the value of this Fraction that you've passed in.
Fraction one = new Fraction(1, 2);
Fraction two = new Fraction(3, 5);
Fraction three = new Fraction(4, 11);
one.add(two); // Inside one's add method, `other` will take on the value 3/5
one.add(three); // Inside one's add method, `other` will take on the value 4/11
three.subtract(two); // Inside three's subtract method, `other` will take on the value 3/5
I hope that helps. I would recommend rewatching the earlier videos about classes, instance variables, and instance methods, as well as the Methods and Parameters video from the Methods unit to help solidfy these concepts. Let me know if you have any other questions!