Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class called MathProgressions which has a main method (NOPE! NO DRIVERS

ID: 640368 • Letter: W

Question

Write a class called MathProgressions which has a main method (NOPE! NO DRIVERS THIS WEEK), and two methods which will calculate the geometric and harmonic progressions via a recursive method.

The class MathProgressions needs to have the following:

Which mean it?s the product of all of the numbers up until that number.

Which means the product of the inverse of the first n numbers.

Example Dialog:

Enter a number and I'll give you the geometric and harmonic sequences

10

Geometric is:

1=1.0 2=2.0 3=6.0 4=24.0 5=120.0 6=720.0 7=5040.0 8=40320.0 9=362880.0 10=3628800.0

Harmonic is:

1=1.0 2=0.5 3=0.16666666666666666 4=0.041666666666666664 5=0.008333333333333333 6=0.0013888888888888887 7=1.9841269841269839E-4 8=2.4801587301587298E-5 9=2.7557319223985884E-6 10=2.7557319223985883E-7

geometric(n) = n × 11

Explanation / Answer

import java.util.Scanner; 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 "); System.out.println( "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(); 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); 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); } public static int geometricRecursive (int n) { if (n == 0) { return 1; } else { return (geometricRecursive(n-1) * n); } } public static int geometricIterative (int n) { int product = 1; for (int index = 1; index
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote