Question

I believe I am doing this right, but I am having issues with my ImproperFraction method in my fraction class outputting properly. It is just to output wither or not the fraction is improper, doesn't have to be anything special.

 public boolean ImproperFraction(Fraction otherObject1){

     if( numerator > denominator) {

          System.out.println("Your fraction is improper and cannot be reduced"); 
          Fraction otherFraction = (Fraction)otherObject1;
          return ((numerator == otherFraction.numerator) && 
             (denominator == otherFraction.denominator));
       }

     else if(numerator <= denominator) {
         System.out.println("Your fraction is proper and has been reduced");
         return false;
       } 

     else {
       return false;
     }     
   }

In the main class:

 System.out.println(ImproperFraction);

The only thing that it is doing is returning false, even though the fraction I put in for it is improper. Thanks for any help!

Was it helpful?

Solution

Well, now that you've shown your entire code - it seems that you're not actually calling the ImproperFraction method anywhere.

You've got a static boolean variable called ImproperFraction which you never actually set, so it's always false. And in the line System.out.println(ImproperFraction), you're printing that variable. But you never call the ImproperFraction method, so the code that you've posted in the actual question (not the pastebin) never runs.

OTHER TIPS

Your problem is that you're only returning true if the numerator and denominator of the current Fraction (the this object) are equal to the numerator and denominator of the fraction that you passed in. That first block should just say

if (numerator >= denominator) {
    System.out.println( "This fraction is improper" );
    return true;
}

and not bother comparing numerators and denominators with otherObject1.

In fact, you should probably not bother passing in otherObject1 at all. You don't need it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top