1. Exercise 6.7 (page 237) in the textbook. Requirements: a) You need to write t
ID: 3708747 • Letter: 1
Question
1. Exercise 6.7 (page 237) in the textbook.
Requirements: a) You need to write two classes for this problem. Name them Investment and InvestmentTest. The associated java files should be Investment.java and InvestmentTest.java. Make sure the two java files are saved at the same location on your computer.
b) The InvestmentTest class should contain only a main method. In this main method, the program takes user inputs of three values – investmentAmount in double, annualRate (annual interest rate) in double, and years in integer. The main method should also invoke a method from the Investment class to print the future value table for 30 years.
c) The Investment class should contain two methods. 1. futureInvestmentValue () – use three parameters (investmentAmount, monthlyInterestRate, and years) to calculate and return the future value. The formula to calculate the future value is futureValue = investmentAmount * Math.pow(1 + monthlyInterestRate, years * 12)
Note that monthlyInterestRate = annualRate / 12 2. printFutureValueTable () – print the future value table for 30 years.
d) Design the printing layout as close of the above example, for 30 years.
e) All the programming style and compiling requirements apply.
Explanation / Answer
Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
Investment.java
---------
public class Investment
{
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
{
double futureValue = investmentAmount * Math.pow(1 + monthlyInterestRate , years * 12) ;
return futureValue;
}
public static void printFutureValueTable(double investmentAmount, double yearlyInterestRate)
{
double val;
double monthlyInterestRate = yearlyInterestRate / 12;
System.out.printf("%-15s %15s ", "Years", "Future Value");
for(int i = 1; i <= 30; i++)
{
val = futureInvestmentValue(investmentAmount, monthlyInterestRate, i);
System.out.printf("%-15d %15.2f ", i, val);
}
}
}
InvestmentTest.java
===============
import java.util.Scanner;
public class InvestmentTest {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double investmentAmount;
double yearlyInterestRate;
System.out.print("Enter investment amount, for example 100: ");
investmentAmount = keyboard.nextDouble();
System.out.print("Enter yearly interest rate, for example 5.25: ");
yearlyInterestRate = keyboard.nextDouble();
yearlyInterestRate /= 100;
Investment.printFutureValueTable(investmentAmount, yearlyInterestRate);
}
}
output
======
Enter investment amount, for example 100: 10000
Enter yearly interest rate, for example 5.25: 3.75
Years Future Value
1 10381.51
2 10777.58
3 11188.76
4 11615.63
5 12058.78
6 12518.83
7 12996.44
8 13492.28
9 14007.02
10 14541.41
11 15096.18
12 15672.12
13 16270.03
14 16890.76
15 17535.16
16 18204.15
17 18898.66
18 19619.67
19 20368.19
20 21145.26
21 21951.98
22 22789.47
23 23658.92
24 24561.54
25 25498.59
26 26471.40
27 27481.32
28 28529.76
29 29618.21
30 30748.18
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.