早教吧 育儿知识 作业答案 考试题库 百科 知识分享

帮忙用textpad写一串JAVA编码,程序要求在下方。答的好的加50分1.Writeaprogramthatreadsininvestmentamount,annualinterestrate,andnumberofyears,anddisplaysthefutureinvestmentvalueusingthefollowingformula:futur

题目详情
帮忙用textpad写一串JAVA编码,程序要求在下方。答的好的加50分
1. Write a program that reads in investment amount, annual interest rate, and number
of years, and displays the future investment value using the following formula:
futureInvestmentValue = investmentAmount(1+monthlyInterestRate)numberOfYears*12
Hint: Use the Math.pow(a, b) method to compute a raised to the power of b.
▼优质解答
答案和解析
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
* 2.9 (Calculatingthe future investment value) Write a program that reads ininvestment amount,
* annual interestrate, and number of years, and display the future investment valueusing the
* followingformula:
futureInvestmentValue =
investmentAmount x(1 + monthlyInterestRate)numberofYears*12
For example, if youentered amount 1000, annual interest rate 3.25%, and number ofyears 1, the future investment value is 1032.98.
Hint:
Use the Math.pow (a,b) method to compute a raised to the power of b.
*/
public class InvestmenntValue{

public static void main(String[] args)throwsIOException {
double investmentAmount =0.0;
double yearlyInterestRate =0.0;
double monthlyInterest =0.0;
int years = 0;
double futureInvestmentValue =0.0;
double temp = 0.0;
BufferedReader my_Buffer;
my_Buffer =newBufferedReader(new InputStreamReader(System.in));
System.out.println("Enter investment amount:" );
investmentAmount =Double.parseDouble(my_Buffer.readLine());
System.out.println("Enter annualinterest rate : " );
yearlyInterestRate =Double.parseDouble(my_Buffer.readLine());
System.out.println("Enter years: ");
years =Integer.parseInt(my_Buffer.readLine());
yearlyInterestRate /=100.0;
monthlyInterest = yearlyInterestRate/ 12.0;
years *= 12;
temp = investmentAmount * (1 +monthlyInterest);
futureInvestmentValue =Math.pow(temp, years);
System.out.println("Answer = "+String.valueOf(futureInvestmentValue));
}
}