d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Decimal To Fraction?
Prev123Next
Add Reply New Topic New Poll
Member
Posts: 13,042
Joined: Apr 12 2008
Gold: 0.00
Nov 7 2014 09:11pm
Quote (Minkomonster @ Nov 7 2014 09:59pm)
Your method is equivalent to mine. You just expanded the ternary operator and gave it meaningful variable names.


Alright, is that what the method is doing essentially?
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 7 2014 09:23pm
Yes.

Have you never taken Algebra in school?
Member
Posts: 13,042
Joined: Apr 12 2008
Gold: 0.00
Nov 7 2014 09:35pm
Quote (Minkomonster @ Nov 7 2014 10:23pm)
Yes.

Have you never taken Algebra in school?


Yup, it's been a while since I've had to find GCF, moreover in a program lol... I just remember finding it in my head though in school lol

Thanks for the help by the way :hug:

This post was edited by DD_Rocking on Nov 7 2014 09:45pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 7 2014 09:50pm
Quote (DD_Rocking @ Nov 7 2014 10:35pm)
Yup, it's been a while since I've had to find GCF, moreover in a program lol... I just remember finding it in my head though in school lol

Thanks for the help by the way  :hug:


Yep.

Now lets see the final product.
Member
Posts: 13,042
Joined: Apr 12 2008
Gold: 0.00
Nov 7 2014 10:55pm
Quote (Minkomonster @ Nov 7 2014 10:50pm)
Yep.

Now lets see the final product.


haha I did get it to work in a non recurring while-loop that is inside of a method that reduces the fractions. In the specifics for this program, we cant use any returns for the reduce method I am using :(

Basically, it has to be a private method that only uses instance variables and return nothing

This post was edited by DD_Rocking on Nov 7 2014 10:56pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Nov 7 2014 10:58pm
Quote (DD_Rocking @ Nov 7 2014 11:55pm)
haha I did get it to work in a non recurring while-loop that is inside of a method that reduces the fractions. In the specifics for this program, we cant use any returns for the reduce method I am using :(


That makes sense. If I was to implement this my reduce method would be a private void method on my Fraction class

I am curious about the while loop though. I can't see why that is needed.

This post was edited by Minkomonster on Nov 7 2014 11:01pm
Member
Posts: 13,042
Joined: Apr 12 2008
Gold: 0.00
Nov 7 2014 11:01pm
Quote (Minkomonster @ Nov 7 2014 11:58pm)
That makes sense. If I was to implement this my reduce method would be a private void method on my Fraction class


yeah hehe thats exactly what it's supposed to be lol
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 7 2014 11:09pm
Quote (Minkomonster @ Nov 7 2014 11:58pm)
That makes sense. If I was to implement this my reduce method would be a private void method on my Fraction class


hmm i'd make it public. if i want a Fraction object to represent 10/100, i'm not sure i want it to auto reduce to 1/10 from the constructor. i'd only want it to auto reduce after performing arithmetic. maybe have a setting for it.

then again, i'm not sure i don't want it to auto reduce from the constructor either. not sure what the downsides are. thats just how apache commons does it iirc, but that's because their equals doesn't first reduce both fractions.

This post was edited by carteblanche on Nov 7 2014 11:12pm
Member
Posts: 13,042
Joined: Apr 12 2008
Gold: 0.00
Nov 7 2014 11:10pm
Quote (carteblanche @ Nov 8 2014 12:09am)
hmm i'd make it public. if i want a Fraction object to represent 10/100, i'm not sure i want it to auto reduce to 1/10 from the constructor. i'd only want it to auto reduce after performing arithmetic. http://onemangaforums.com/public/style_emoticons/default/shrug.gif

then again, i'm not sure i don't want it to auto reduce from the constructor either. not sure what the downsides are. thats just how apache commons does it iirc


hmm, would it change what the result of the arithmetic would be?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 7 2014 11:12pm
Quote (DD_Rocking @ Nov 8 2014 12:10am)
hmm, would it change what the result of the arithmetic would be?


up to you. if you want to add 1/2 and 1/2, would you want it to be 2/2 or 1/1? would you consider 2/2 and 1/1 to be equal?

This post was edited by carteblanche on Nov 7 2014 11:12pm
Go Back To Programming & Development Topic List
Prev123Next
Add Reply New Topic New Poll