digitalgangster dot com
 
  these are ads that support the board lol internet:

ytcracker tour is looking more like NEXT YEAR!
TAG is having problems placing dates that make sense.
sorry.
:: click here for a special announcement ::

REGISTER AN ACCOUNT TO GET RID OF THE ADS

Go Back   digitalgangster dot com > dg4l > margorp/whywork

Reply
 
Thread Tools Display Modes
Old 11-03-2009, 07:44 PM   #1
Riku
 
Join Date: Sep 2009
Posts: 32
Default Simplifying Fractions on Java

I'm making a Fraction calculator and i've gotten to the point where i can solve it to it's final answer, the only problem i'm stumped on is how to simplify the final answer. plz help
Ban This User Riku is offline   Reply With Quote
Old 11-03-2009, 08:26 PM   #2
Gray
internet moneymaker wannabe.
 
Gray's Avatar
 
Join Date: Feb 2009
Location: seattle. wa
Posts: 277
Send a message via AIM to Gray Send a message via MSN to Gray
Default

lookup how modulo works, you'll need to find remainders here.
__________________

Quote:
Originally Posted by The Iron Lung View Post
Jesus Christ you are one fucked up dude. have you considered therapy? I hope you get the help you so desperately need.
Ban This User Gray is offline   Reply With Quote
Old 11-03-2009, 08:29 PM   #3
nox
 
nox's Avatar
 
Join Date: Jan 2008
Location: no love for bitches
Posts: 4,183
Default

divide the fraction each number of the fraction by the denominator.. if the denominator yields a non integer # then its no good

Last edited by nox; 11-03-2009 at 08:34 PM.
Ban This User nox is offline   Reply With Quote
Old 11-04-2009, 09:13 AM   #4
ack
 
Join Date: Jan 2009
Posts: 161
Default

find the least common factors of the denominator and numerator and just cancel like terms... unless i'm missing the point do you have like Integer1/Integer2 ?
__________________

music songs
Ban This User ack is online now   Reply With Quote
Old 11-04-2009, 12:06 PM   #5
pimpleon
We Gettin -بجدية Money!
 
pimpleon's Avatar
 
Join Date: Sep 2008
Location: Fla.
Posts: 4,985
Send a message via AIM to pimpleon Send a message via MSN to pimpleon
Default

uhmm
create a new class
and you're gonna have to do it contructor style like how ure last thread was...

and try this
Code:
private void Reduce(){
    	int a = numerator;
    	int b = denominator;
    	int c = 0;

    	while( b!= 0 )
    	{
    		c = a % b;
    		a = b;
    		b = c;
    	}
    	denominator/=a;
    	numerator/=a;
    }

i did this last week in my comp sci class.
__________________
Current PimpLeon Logo - Gmh - I Fucked Your Mother
- -
Ban This User pimpleon is offline   Reply With Quote
Old 11-04-2009, 12:40 PM   #6
mx
 
mx's Avatar
 
Join Date: May 2005
Posts: 5,592
Default

Quote:
Originally Posted by pimpleon View Post
uhmm
create a new class
and you're gonna have to do it contructor style like how ure last thread was...

and try this
Code:
private void Reduce(){
    	int a = numerator;
    	int b = denominator;
    	int c = 0;

    	while( b!= 0 )
    	{
    		c = a % b;
    		a = b;
    		b = c;
    	}
    	denominator/=a;
    	numerator/=a;
    }

i did this last week in my comp sci class.
wtf is this shit

Code:
package reduce;

public class Reduce
{
       private int numerator;
       private int denominator;

        public static void main (String[] args)
        { 
            Reduce(2, 4); // example call
        }

        public void Reduce(int numerator, int denominator)
        {
        	int numerator = this.numerator;
        	int denominator = this.denominator;
        	int c = 0;

        	while( b != 0 )
        	{
    	        	c = numerator % denominator;
    	        	numerator = denominator;
    		        denominator = c;
    	         }

    	denominator/=a;
    	numerator/=a;

        System.out.print(numerator + "\n" + denominator);
    }
}
Ban This User mx is offline   Reply With Quote
Old 11-04-2009, 04:32 PM   #7
pimpleon
We Gettin -بجدية Money!
 
pimpleon's Avatar
 
Join Date: Sep 2008
Location: Fla.
Posts: 4,985
Send a message via AIM to pimpleon Send a message via MSN to pimpleon
Default

lol mx. basically the same thing broe...

i had it so he'd have to create another class cause in hte OP he said he got everything down but the reducing...
so when it was done evaluating what ever code he did have he'd just have to put
Reduce(numerator,denominator);
in his main class, without him havin to change up or move his code around
__________________
Current PimpLeon Logo - Gmh - I Fucked Your Mother
- -
Ban This User pimpleon is offline   Reply With Quote
Old 11-04-2009, 04:39 PM   #8
hudscappe
 
Join Date: Nov 2009
Posts: 1
Default

Great post! It's very nice and userful. Thank you so much for Paul post.
Ban This User hudscappe is offline   Reply With Quote
Reply



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:58 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
(c)2001-infinity digital gangster enterprises, llc
ytcracker is king of the internet. stc is the greatest.