/**
* Takes a Fraction object and reduces it to it's lowest level, including
* accounting for whole numbers, and then returns a string
* @param frac Fraction the fraction to be recuded
* @return String the output of the reduced fraction
*/
public static String reduceFraction(Fraction frac){
// Get Current Numerator, and Denominator
int num = frac.getNumerator();
int den = frac.getDenominator();
// Create and Initilize variables for output
String output = "";
int whole = num/den;
// If the Numerator is greator than the Denominator, then remove the
// whole number, and save it to the string.
if (whole>=1){
output = Integer.toString(whole) + " ";
num = num - (whole * den);
}
// If there is any remainder from the removing of whole numbers, then
// divide both the Numerator and Denominator by half of the Denominator
// untill both have no remainder, then apply.
// Append to Output if this was run, otherwise output will remain as
// the whole number from above.
if (num > 0){
for (int i=(den/2); i>1; i--){
if ((den % i == 0) && (num % i == 0)){
num = num / i;
den = den / i;
}
}
output += num + "/" + den;
}
return output;
}