Hi...
I've been trying to edit and rewrite my code for quite a while now but no matter what I do the program only ever reads the last instance of a class that I declare.
For example,
Fraction ni = new Fraction(3,4);
System.out.println(Fraction.lcd(ni,new Fraction(3,2)));
> This code is supposed to get the lcd of 3/4 and 3/2. It gives me a 2.
When I have this:
Fraction ichi = new Fraction(1,6);
Fraction ni = new Fraction(3,4);
System.out.println(Fraction.lcd(ni,ichi));
It gives me the result of 4. T_T
For reference, this is the code I have created for getting the LCD:
public static int lcd(Fraction fracA, Fraction fracB){
if(fracA.getDenominator()%fracB.getDenominator() == 0)
denum = fracA.getDenominator();
else if(fracB.getDenominator()%fracA.getDenominator() == 0)
denum = fracB.getDenominator();
else
denum = fracA.getDenominator()*fracB.getDenominator();
return denum;
}
The problem is that I can never get the correct answer because everytime I create another instance, it only reads that one and not the previosly declared ones.