public RationalFraction add RationalFraction rat RationalFraction rt i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
public RationalFraction add(RationalFraction rat) {
RationalFraction rt
if (x * y == 0) {
rt = new RationalFraction(rat.getX(), rat.getY());
} else {
rt= new RationalFraction(x * rat.getY() + rat.getX() * y, y * rat.getY());
}
rt.reduce();
return rt;
}
public void add2(RationalFraction rat) {
if(x * y == 0) {
x = rat.getX();
y = rat.getY();
} else {
x = x * rat.getY() + rat.getX() * y;
y = y * rat.getY();
}
reduce();
}