So far, I have this, and I have more to go, but I'm confused about something. Ok, I'm supposed to use this as a function:
public Rational add(Rational a)
and then call something like:
Rational r3 = r1.add(r2);
I haven't seen any implementation on this before, any help would be appreciated on how to write the add function.
public class Rational {
private int numerator;
private int denominator;
public void setNumerator(int n) {
numerator = n;
}
public void setDenominator(int d) {
denominator = d;
}
public Rational() {}
public Rational(int n, int d) {
numerator = n;
denominator = d;
}
public Rational add(Rational a) {
}
}
Question
LRoling
So far, I have this, and I have more to go, but I'm confused about something. Ok, I'm supposed to use this as a function:
public Rational add(Rational a)
and then call something like:
Rational r3 = r1.add(r2);
I haven't seen any implementation on this before, any help would be appreciated on how to write the add function.
Link to comment
https://www.neowin.net/forum/topic/232590-java-adding-rational-numbers/Share on other sites
6 answers to this question
Recommended Posts