+ 1

How to solve this fraction problem?

public FractionInterface add(FractionInterface secondFraction) { // implement this method! // a/b + c/d is (ad + cb)/(bd) // invoke covert() and reduce() before return the result Fraction newFraction = new Fraction(num,den); secondFraction.num = newFraction.num*secondFraction.den + newFraction.den*secondFraction.num; secondFraction.den = newFraction.den * secondFraction.den; setFraction(secondFraction.num,secondFraction.den); secondFraction.convert(); secondFraction.reduce(); return secondFraction; } // end add the first fraction is firstOperand = new Fraction(7, 8); and the second fraction is (9,16); and should pass the class"public FractionInterface add" like Fraction nineSixteenths = new Fraction(9, 16); double result = firstOperand.add(nineSixteenths); after add, the result should be (7*16 + 9*8)/(8*16); my problem is how to get the secondFration num and den`s value. as my code, secondFraction.num is an error because num cannot be resolved or is not a field. how to solve this isuue? thanks

18th Mar 2019, 3:00 AM
Chaoyi Ying
Chaoyi Ying - avatar
1 Antwort
+ 1
Fraction and FractionInterface appears to be a self-defined class and interface. Without the full code, it's a little hard to tell what getters and setters we can use, and what other methods are available to be utilized. Can you provide the full code, or at least the class definition of Fraction and FractionInterface?
18th Mar 2019, 4:55 AM
Fermi
Fermi - avatar