gram calculates the geometric and harmonic progression for a number entered by the user. */ public class Progression {
import java.util.Scanner;
/**
This
harmonic progression for a number entered
by the user.
*/
public class Progression
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
System.out.println("This program will calculate " +
"the geometric and harmonic " +
"progression for the number " +
"you enter.");
System.out.print("Enter an integer that is " +
"greater than or equal to 1: ");
int input = keyboard.nextInt();
// Match the method calls with the methods you write
int geomAnswer = geometricRecursive(input);
double harmAnswer = harmonicRecursive(input);
System.out.println("Using recursion:");
System.out.println("The geometric progression of " +
input + " is " + geomAnswer);
System.out.println("The harmonic progression of " +
input + " is " + harmAnswer);
// Match the method calls with the methods you write
geomAnswer = geometricIterative(input);
harmAnswer = harmonicIterative(input);
System.out.println("Using iteration:");
System.out.println("The geometric progression of " +
input + " is " + geomAnswer);
System.out.println("The harmonic progression of " +
input + " is " + harmAnswer);
}
// ADD LINES FOR TASK #2 HERE
// Write the geometricRecursive method
// Write the geometricIterative method
// Write the harmonicRecursive method
// Write the harmonicIterative method
}
![Lab Objectives
• Be able to trace recursive function calls
Be able to write non-recursive and recursive methods to find geometric and
harmonic progressions.
Introduction
In this lab we will follow how the computer executes recursive methods, and will write
our own recursive method, as well as the iterative equivalent. There are two common
progressions in mathematics, the geometric progression and the harmonic progression.
The geometric progression is defined as the product of the first n integers. The harmonic
progression is defined as the product of the inverses of the first n integers.
Mathematically, the definitions are as follows:
n-1
Geometric (n) =
i=l
i=l
n-1
1
1
П
П
*
-
Harmonic (n) =
Let's look at examples.
If we use n = 4, the geometric progression would be 1 * 2 * 3 * 4 = 24, and the harmonic
1,1,1 1
progression would be 1*-*-
0.04166.
2 3 4 24](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff55a0088-1769-4f20-8495-36414e93366d%2Fc890d58c-337b-4c30-a2c7-6349d2957b0e%2Fun2ju36_processed.jpeg&w=3840&q=75)
![Task #2 Writing Recursive and Iterative Versions of a Method
1. Copy the file Progression.java (see code listing 16.2) from the Student Files or
as directed by your instructor.
2. You need to write class (static) methods for an iterative and a recursive
version of cach of the progressions. You will create the following methods:
a. geometricRecursive
b. geometricIterative
c. harmonicRecursive
d. harmonicIterative.
Be sure to match these methods to the method calls in the main method.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff55a0088-1769-4f20-8495-36414e93366d%2Fc890d58c-337b-4c30-a2c7-6349d2957b0e%2Fsemk59_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)