How to solve "int cannot be dereferenced" error?
Hello, I'm getting an "int cannot be dereferenced error" with my method. I'm trying to add two rational numbers
(fractions) together and return the new rational number.
From what I've read in my book and online, I've figured out that I can't invoked methods on primitives.
But then how else would I get the numerator and denominator of the two rational numbers?
Any help is greatly appreciated, thanks!
public RationalNumber add(RationalNumber other)
this.numerator = number.getNumerator() * other.getNumerator()
+ number.getDenominator() * other.getDenominator();
this.denominator = number.getDenominator() * other.getDenominator();
RationalNumber addedNumber = new RationalNumber(addNumerator, addDenominator);
Re: How to solve "int cannot be dereferenced" error?
Quite possibly with .numerator and .denominator as you are already doing with "this". But that's only a guess.
how else would I get the numerator and denominator of the two rational numbers?
For better, post the Rational class so we can see how it's defined. And the full and exact compiler message. Also say precisely what this method is supposed to do. At the moment you have it doing two things: creating and return a new Rational, and also altering the state of "this".
Also you might want to check your formula. a/b +c/d != (ac+bd)/bd