Results 1 to 4 of 4
  1. #1
    tonyboy00 is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    tonyboy00 is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default 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. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: product of fractions

    Quote Originally Posted by tonyboy00 View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Fractions
    By Kartright in forum New To Java
    Replies: 23
    Last Post: 05-30-2013, 04:12 PM
  2. Fractions equals each other problem
    By LetsG0Blue in forum New To Java
    Replies: 12
    Last Post: 03-12-2013, 08:31 AM
  3. trouble using fractions
    By jeanOliver in forum New To Java
    Replies: 2
    Last Post: 09-06-2011, 08:48 PM
  4. Reducing fractions
    By SwEeTAcTioN in forum New To Java
    Replies: 10
    Last Post: 01-13-2010, 04:51 PM
  5. How do I reduce Fractions in this program?
    By Popedreadlock in forum New To Java
    Replies: 8
    Last Post: 12-08-2008, 12:28 AM

Posting Permissions

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