Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Lowest Term Function Help

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Lowest Term Function Help

    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?
    Last edited by thisbeme; August 1st, 2011 at 07:15 AM. Reason: Wrong


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Lowest Term Function Help

    Quote Originally Posted by thisbeme View Post
    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.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Lowest Term Function Help

    Quote Originally Posted by Sean4u View Post
    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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Lowest Term Function Help

    still have a problem with my code
    Please explain the problem.
    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.

  5. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Lowest Term Function Help

    Quote Originally Posted by Norm View Post
    Please explain the problem.
    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

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Lowest Term Function Help

    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?
    Given that we can help you code it in java.

Similar Threads

  1. Long term project work from home developer
    By internext in forum Paid Java Projects
    Replies: 17
    Last Post: May 2nd, 2012, 07:51 PM
  2. Replies: 1
    Last Post: December 4th, 2010, 04:26 PM
  3. Loop to note position of lowest number
    By fortune2k in forum Loops & Control Statements
    Replies: 3
    Last Post: November 23rd, 2010, 09:05 AM
  4. Java Web Browser Term Project- I am facing multiple problem...pls help
    By tazbinur in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 8th, 2010, 09:05 AM
  5. Function of difference between two numbers
    By uplink600 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 13th, 2009, 05:57 AM