📄 exercise2_12.java
字号:
// Exercise2_12.java: Create a method for computing future value
import javax.swing.JOptionPane;
public class Exercise2_12 {
public static void main(String[] args) {
// Enter yearly interest rate
String annualIntrestRateString = JOptionPane.showInputDialog(
"Enter yearly interest rate, for example 8.25:");
// Convert string to double
double annualInterestRate =
Double.parseDouble(annualIntrestRateString);
// Obtain monthly interest rate
double monthlyInterestRate = annualInterestRate/1200;
// Enter number of years
String numOfYearsString = JOptionPane.showInputDialog(
"Enter number of years as an integer, \nfor example 5:");
// Convert string to int
int numOfYears = Integer.parseInt(numOfYearsString);
// Enter the investment amount
String investmentAmountString = JOptionPane.showInputDialog(
"Enter the investment amount, for example 120000.95:");
// Convert string to double
double investmentAmount = Double.parseDouble(investmentAmountString);
double futureValue =
investmentAmount * Math.pow(1 + monthlyInterestRate,
numOfYears * 12);
System.out.print("Future value is " +
(int)(futureValue * 100) / 100.0);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -