Question: Use Java and Eclipse to develop a program that implements Euclid's algorithm for finding the greatest common divisor of two positive integers. The inputs to

Use Java and Eclipse to develop a program that implements Euclid's algorithm for finding the greatest common divisor of two positive integers.

The inputs to the algorithm will be supplied as command line arguments when the program is executed.

Program Design

This assignment requires only a single public class "Euclid", which will be in the file "Euclid.java" in the "Euclid" project in Eclipse.

You can develop this class without using any class variables, instance variables, or instance methods

This program can be implemented using only a few local integer variables. Neither arrays nor array lists, nor any other complex objects are required, but you may use them if you wish.

The Euclid class can consist of only two methods: main() and a support method.

The main method should input the two command arguments as integer variables. This method should also output the required output header to the console (as described in the output section below) and then simply pass the two integer variables to the support method.

The support method should be a static (i.e., class) method with a "void" return type. You may give this method any name you wish, as long as it is a valid Java identifier. This method should apply Euclid's algorithm (described below) to the two input arguments. The method should report to the console the intermediate values in the format shown below, and when the algorithm completes, it should output to the console the final result, also in the format shown below.

Euclid's Algorithm

Euclid's algorithm computes the greatest common divisor of two input positive integers. The greatest common divisor is the largest positive integer that divides evenly into both of the input values.

The algorithm uses the Definition of Division, which states that for any two integers a and b, there exist integers q and r such that a = q ( b ) + r. In this representation, q is the quotient and r is the remainder.

Given two positive integers a and b, the algorithm proceeds as follows:

For the given values of a and b, apply the Definition of Division and compute the quotient q and remainder r;

If r > 0, then update a and by by assigning the value of b to a and also assigning the value of r to b, and then repeat Step 1 with the updated values.

If r = 0, then the greatest common divisor of the original a and b is the last computed non-zero value for r.

A complete example of the operation of the algorithm is shown in the required output section below

Required Output Format

The required format is shown below:

----------------------------------------------------

Euclid's Algortihm by :

Inputs: 5763, 187

5763 = 30 ( 187 ) + 153

187 = 1 ( 153 ) + 34

153 = 4 ( 34 ) + 17

34 = 2 ( 17 ) + 0

==> gcd( 5763, 187) = 17

The main method should output the following as the output header:

an empty line

a line of just hyphens (dashes)

another empty line

the words "Euclid's Algorithm by " followed by your name (or names, if teaming

another empty line

the word "Inputs: " followed by the two input values in the order they were input, separated by a comma

another empty line

The support method should output the remainder of the lines shown, including empty lines. Each line of the intermediate output shows the values of a, b, q, and r, in the format of the Definition of Division. The last nonempty line identifies and reports the value of the the greatest common divisor.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!