【问题标题】:Amortization example摊销示例
【发布时间】:2018-03-26 14:49:55
【问题描述】:

这是我的代码:

  public class exampleaAmortizationProgram {
 public static void main(String[] args) {
     Scanner input = new Scanner(System.in);

     System.out.printf("Loam amount");
     double loamAmount = input.nextDouble();

     System.out.print("Number of Years:");
     int numberOfYears = input.nextInt();

     System.out.print("Annual Interest Rate(8.25): ");
     double annualInterestRate = input.nextDouble();

     double monthlyInterestRate = annualInterestRate / 1200;

     //compute mortgage 
     double monthlyPayment = monthlyPayment(loamAmount, numberOfYears, monthlyInterestRate);

     double balance = loamAmount;
     double interest;
     double principal;

     System.out.println("Monthly Payment: " + monthlyPayment * 100/ 100.0);
     System.out.println("Total Payment: " + monthlyPayment * 12 + numberOfYears * 100/ 100.0 + "\n");

    DecimalFormat df = new DecimalFormat("0.00");

    for (int i = 1; i <= numberOfYears * 12; i++) {
        interest = monthlyInterestRate * balance * 100 / 100.0;
        principal = monthlyPayment - interest * 100 / 100.0;
        balance = balance - principal * 100 / 100.0;

        System.out.println(i + "\t\t" + df.format(interest) + "\t\t" + df.format(principal) + "\t\t" + df.format(balance));
    }       
    }
private static double monthlyPayment(double loamAmount, int numberOfYears, double monthlyInterestRate) {
    double monthlyPayment = loamAmount + monthlyInterestRate / (1 - (Math.pow(1 / (1 + monthlyInterestRate), numberOfYears * 12)));
    return monthlyPayment;
}
}

我查看了执行 DecimalFormat 的不同方法,但它仍然说我在该代码源中有一个错误:

exampleaAmortizationProgram.java:44: error: 
cannot find symbol DecimalFormat df = new DecimalFormat("0.00"); 

请帮忙。

【问题讨论】:

  • exampleaAmortizationProgram.java:44: 错误:找不到符号 DecimalFormat df = new DecimalFormat("0.00"); ^
  • 在你的系统输出中你有“-”而不是“+”: System.out.println(i + "\t\t" + df.format(interest) + "\t\t" !!!!!!-!!!!!! df.format(principal) + "\t\t" + df.format(balance));
  • 请展示完整的源代码。这些变量如何被初始化?
  • 在 System.out.print 中有„-„。如果要减法,则需要将其放入另一个“()”中。
  • 公共类 exampleaAmortizationProgram { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.printf("壤土量");双 loamAmount = input.nextDouble(); System.out.print("年数:"); int numberOfYears = input.nextInt(); System.out.print("年利率(8.25):");双倍年利率 = input.nextDouble();双月利率 = 年利率 / 1200;

标签: java decimalformat


【解决方案1】:

System.out.println(i + "\t\t" + df.format(interest) + "\t\t" - df.format(principal) + "\t\t" + df.format(balance));

那里有„-„。

【讨论】:

    猜你喜欢
    • 2013-11-08
    • 2013-07-02
    • 1970-01-01
    • 2016-03-16
    • 2015-05-04
    • 2018-02-13
    • 2010-09-17
    相关资源
    最近更新 更多