📄 exercise4_3.java
字号:
// Exercise4_3.java: Create a method for computing future value
import javax.swing.JOptionPane;
public class Exercise4_3 {
public static void main(String[] args) {
// Enter yearly interest rate
String annualIntrestRateString = JOptionPane.showInputDialog(
null, "Enter yearly interest rate, for example 8.25:",
"Exercise 4_3 Input", JOptionPane.QUESTION_MESSAGE);
// Convert string to double
double annualInterestRate =
Double.parseDouble(annualIntrestRateString);
// Enter loan amount
String loanString = JOptionPane.showInputDialog(null,
"Enter loan amount, for example 120000.95:",
"Exercise 4_3 Input", JOptionPane.QUESTION_MESSAGE);
// Convert string to double
double loanAmount = Double.parseDouble(loanString);
System.out.println("Years\tFuture Value");
for (int i = 1; i <= 30; i++) {
double futureValue =
futureInvestmentValue(loanAmount, annualInterestRate / 1200, i);
System.out.println("" + i + "\t" + (int)(futureValue * 100) / 100.0);
}
System.exit(0);
}
public static double futureInvestmentValue(double investmentAmount,
double monthlyInterestRate, int numOfYears) {
return investmentAmount * Math.pow(1 + monthlyInterestRate,
numOfYears * 12);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -