# Lowest Term Function Help

• August 1st, 2011, 06:01 AM
thisbeme
Lowest Term Function Help
Code :

```public class RectangleDos{   public static int num; public static int den; public double val;   public void display(){ System.out.println("FRACTION: " + num + "/" + den); }     public int GCD(int a, int b) { while (a != 0 && b != 0) { if (a > b) a %= b; else b %= a; }   if (a == 0) return b; else return a; }   public double doubleValue(){ val = num * 1.0 / den * 1.0; return val; }           public static void main(String[] args) { int u; RectangleDos x = new RectangleDos(); x.num =77; x.den =11;   x.display();   System.out.println("DOUBLEVALUE: " + x.doubleValue());   System.out.println(x.GCD(num, den));     } }```

I already solved my first problem on how to find the GCD. Now I need to make a new function which is Simplify(), wherein it will give the lowest term of the numerator and the denominator. I already got the GCD, so how do I throw in that value to the Simplify function to divide the numbers?
• August 1st, 2011, 06:22 AM
Sean4u
Re: Lowest Term Function Help
Quote:

Originally Posted by thisbeme
Care to help?

I can't decide whether I can help without spoonfeeding or not.
This is what you're trying to do: Greatest common divisor - Wikipedia, the free encyclopedia
You have to write Euclid's algorithm at least once yourself before you use the method in BigInteger - it's a rite of passage thing.
• August 1st, 2011, 07:17 AM
thisbeme
Re: Lowest Term Function Help
Quote:

Originally Posted by Sean4u
I can't decide whether I can help without spoonfeeding or not.
This is what you're trying to do: Greatest common divisor - Wikipedia, the free encyclopedia
You have to write Euclid's algorithm at least once yourself before you use the method in BigInteger - it's a rite of passage thing.

im sorry i was to lazy to search about it. well anyways thanks about that euclid's algorith thing, i tried to search it and somehow i got how it works. thanks again.

but i still have a problem with my code. hope you can help me
• August 1st, 2011, 08:35 AM
Norm
Re: Lowest Term Function Help
Quote:

still have a problem with my code
Does it compile?
Does it execute?
Does it generate output? Is the output correct? If not, explain what is wrong with it and what it should be.
• August 2nd, 2011, 12:11 AM
thisbeme
Re: Lowest Term Function Help
Quote:

Originally Posted by Norm
Does it compile?
Does it execute?
Does it generate output? Is the output correct? If not, explain what is wrong with it and what it should be.

yes it execute and compile but...

I still need to make a new function which is Simplify(), wherein it will give the lowest term of the numerator and the denominator. I already got the GCD, so how do I throw in that value of the GCD to the Simplify function to divide the numbers?

Hope you can help me. thanks in advance :)
• August 2nd, 2011, 06:33 AM
Norm
Re: Lowest Term Function Help
Quote:

I still need to make a new function which is Simplify(), wherein it will give the lowest term of the numerator and the denominator.
Do you have the algorithm for finding them?