What is Fraction Reduction to Lowest Term? | Maths Explanation for Java Kids
Reducing fractions to their lowest terms is all about
removing every common factor between the numerator and
the denominator.
In this junior secondary Java tutorial, you'll learn how to simplify fractions using a custom module.
The Java code provided helps reduce fractions to their lowest terms by finding common factors between the numerator and denominator.
Whether you're a student or teacher, this math-focused Java project makes fraction simplification easy and fun.
How the Reduce Fraction to Lowest Term Method Works | Detailed Explanation for Java Kids
Let's see a Java algorithm implementation to reduce a fraction to it's lowest term, using 12/16 as an example fraction.
A common factor to 12 and 16 is 2;
so removing 2 from 12/16 yields
6/8.
Again, 2 is common to both 6 and 8;
removing it yields 3/4.
We stop when nothing else is common (1 does not count).
Create a new Java class file;
call it LowestTerm.
Type out the adjoining Java code for reducing fractions to their lowest terms.
Note: You can comment out the ImproperToMixed Java object
code in the main class from the previous lesson or simply continue from where it stopped.
So! Java Fun Practice Exercise - Reduce Fraction to Lowest Term
As a fun practice exercise, feel free to try out your own fractions with different numerators and denominators,
and see how the Java code simplifies those fractions.
Java Code for Reducing Fractions to Lowest Term - Class File
package algebra;
public class LowestTerm {
protected int numerator;
protected int denominator;
protected int trial_factor;
public LowestTerm(int num, int denom) {
numerator = num;
denominator = denom;
if (num < denom) {
trial_factor = num;
} else {
trial_factor = denom;
}
}
public int[] reduceFraction() {
while (trial_factor > 1) {
if ((numerator % trial_factor) == 0) {
if ((denominator % trial_factor) == 0) {
numerator /= trial_factor;
denominator /= trial_factor;
continue;
}
}
trial_factor--;
}
return new int[]{numerator, denominator};
}
}
Java Code for Reducing Fractions to Lowest Term - Main Class
package algebra;
public class Algebra {
public static void main(String[] args) {
int numerator;
int denominator;
int[] solution;
System.out.println("Welcome to our demonstration sequels");
System.out.println("Hope you enjoy (and follow) the lessons.");
System.out.println("");
numerator = 16;
denominator = 640;
System.out.println("To reduce to lowest term, simplifying:");
System.out.printf("%45d%n", numerator);
System.out.printf("%44s%n", "―");
System.out.printf("%45d%n", denominator);
LowestTerm red_fract = new LowestTerm(numerator, denominator);
solution = red_fract.reduceFraction();
numerator = solution[0];
denominator = solution[1];
System.out.println();
System.out.printf("%46d%n", numerator);
System.out.printf("%45s%n", "Answer = ―");
System.out.printf("%46d%n", denominator);
System.out.println("\n\n");
}
}