⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exercise2_12.java

📁 java程序设计导论(daniel liang著) 所有偶数课后习题答案
💻 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 + -