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

GeometricMean A home purchased for 300,000 dollars increases in value by 10% aft

ID: 3681097 • Letter: G

Question

GeometricMean
A home purchased for 300,000 dollars increases in value by 10% after one year and by another 20% after a second year. Thus, a year after purchasing the house, its value is 1.10 300,000 dollars and after two years 1.20 1.10 300,000 dollars. A third year decrease of 6% drops the value to 94% of the previous value. 0.94 1.20 1.10 300000 372240 dollars. Notice that the multiplier is 1 0.06 0.94. The average annual increase over the three-year period is the geometric mean of 1.10, 1.20 and 0.94.

In general, the geometric mean of n numbers is the nth root of their product. Thus, the geometric mean of 1.10, 1.20, and .94 is (1.10 1.20 .94)1/3 1.074568 and the product 1.074568 1.074568 1.074568 300000 equals 372240, as does the original product, .94 1.20 1.10 300000. In other words, the home’s value after three annual changes of 10%, 20%, and 6% is the same as if, each year, the home’s value increased by 7.4568%.

Write a program that calculates the average increase or decrease on an investment held from one to six years. Your program should rst prompt for the length of time of the investment (an integer between 1 and 6, inclusive) and then the percent increase or decrease for each year. A negative number indicates a decrease. The program should display the average annual increase or decrease. For example, if a home, over a six-year period, has changed in value by 10%, 20%, 6%, 8%, 12%, and 3%, then to compute the average annual increase (or decrease), you would calculate the geometric mean of 1.1, 1.2, 1.06, 0.92, 0.88, and 1.03.

Hints: Overload a method, geometricMean(...). Make ve versions that have two, three, four, ve, and six parameters of type double. Use Math.pow(x,y).

Explanation / Answer

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Test{ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the length of time of the investment (an integer between 1 and 6, inclusive):"); int length = Integer.parseInt(br.readLine()); double[] delta = new double[length]; System.out.println("Enter the percent increase or decrease for each year:"); double product = 1; for(int i=0; i0){ delta[i] = 1 + (d/100); }else { delta[i] = 1 - (d/100); } product = product * delta[i]; } double gm = Math.pow(product,(1/length)); System.out.println("Geometric mean = "+gm); } }
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