1. Member
Join Date
Nov 2013
Posts
2
Rep Power
0

## product of fractions

Hi to all ,sorry fo my bad english. I have the following code Java (is it just a meaningless example ), my question is: if I wanted to insert a code to multiply two fraction into moltiplicaPer() metod What should I write? Thx in advance. Antonio

public class Frazione {

private int num;
private int den;

Frazione() {
num = 0;
den = 1;
}

Frazione(int a, int b) {
num = a;
den = b;

}

public void moltiplicaPer(Frazione f2) {

//insert code here...
}

}//end class

2. ## Re: product of fractions

Well, mathematically the product of two fractions n1/d1 and n2/d2 is (n1*n2)/(d1*d2); it won't be much different in Java code ...

kind regards,

Jos

3. Member
Join Date
Nov 2013
Posts
2
Rep Power
0

## Re: product of fractions

Thanks, but I wanted this mean:

public void moltiplicaPer(Frazione f2){
Frazione r = new Frazione();
r.num = f2.num * num;
r.den = f2.den * den;
}

4. ## Re: product of fractions

Originally Posted by tonyboy00
Thanks, but I wanted this mean:

Java Code:
```public void moltiplicaPer(Frazione f2){
Frazione r = new Frazione();
r.num = f2.num * num;
r.den = f2.den * den;
}```
Yep, that's close but you should return the new Frazione r and maybe simplify the numerator and denominator.

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•