Lab 5: Greatest Common Divisor

Due by the end of class

Your mission is to read in the numerator and the denominator of a fraction, compute the greatest common divisor (GCD), then print the fraction in lowest terms.

If the notion of GCD has slipped out of your head momentarily, it's simply the largest integer that evenly divides two other integers.

For example, the fraction 39/91 is not in lowest terms. Both 39 and 91 are evenly divisible by 13, their GCD. Thus, this fraction in lowest terms is 3/7.

Specification

Create a project called Lab5. Add a class called GCD. Complete a program that reads in a numerator (as an int) and a denominator (again, as an int), computes and outputs the GCD, and then outputs the fraction in lowest terms. Write your program so that your output looks as close to the following sample output as possible. In this sample, the user entered 42 and 56, shown in green.

Enter the numerator: 42
Enter the denominator: 56
The GCD is: 14
The fraction in lowest terms is: 3/4

You should use a while loop to complete this assignment. I recommend that you simply do trial divisions. Start at 1 and then keep trying to divide both numbers by an increasingly larger value. Hint: a number a divides a number b evenly when the remainder of the division is 0. Your loop should stop when it reaches either of the numbers you are trying to find the GCD for.

Remember that you will need some way to keep track of the largest divisor you have found so far. Alternatively, you could start at the smaller of the two numbers and go downward. Then, the first number you find that divides both is the answer.

Turn In

Turn in your code by uploading GCD.java from the Lab5\src folder wherever you created your project to Blackboard. Do not upload the entire project. I only want the GCD.java file.

All work must be done individually. Never look at someone else's code. Please refer to the course policies if you have any questions about academic integrity. If you have trouble with the assignment, I am always available for assistance.