gpt4 book ai didi

java - 计算 APY 并使用 java 中的另一种方法

转载 作者:行者123 更新时间:2023-12-01 15:03:38 26 4
gpt4 key购买 nike

我似乎无法让它发挥作用。我正在尝试从主方法中获取 APY 和 Loan payment 的结果

我不断收到消息称找不到compoundingOption符号。有人能检测到这里的错误吗?

public class Finance {

public static void main(String [] args) {
// Practice myPractice = new Practice();
System.out.println(computeApy(5.50, 1));
System.out.println(computeLoanPayment(20000.00, 7.5, 15.0, 1));
}

public static double computeApy(double annualRate, int compoundingOption) {
// APY = (1 + (r/n))^n - 1

// daily
if (compoundingOption == 1) {
return (Math.pow((1 + (annualRate / 365)), 365)) - 1;
// monthly
}
else if (compoudingOption == 2) {
return (Math.pow((1 + (annualRate / 12)), 12)) - 1;
// annually
}
else if (compoudingOption == 3) {
return (Math.pow((1 + (annualRate / 1)), 1)) - 1;
}
else {
return -1;
}
}

public static double computeLoanPayment(double principal, double annualRate, double yearsDuration,
int paymentOption) {
// A = P * r(1+r)^n / (1+r)^n - 1
// biweekly
if (paymentOption == 1) {
return principal * (annualRate * Math.pow((1 + annualRate), 26)) / ((Math.pow((1 + annualRate), 26)) - 1);
// monthly
}
else if (paymentOption == 2) {
return principal * (annualRate * Math.pow((1 + annualRate), 12)) / ((Math.pow((1 + annualRate), 12)) - 1);
// quarterly
}
else if (paymentOption == 3) {
return principal * (annualRate * Math.pow((1 + annualRate), 4)) / ((Math.pow((1 + annualRate), 4)) - 1);
}
else
return -1;
}
}

最佳答案

您在第二个和第三个 block 中拼错的compoudingOption

缺少“n”

您有 compoudingOption 并且变量是compoundingOption

关于java - 计算 APY 并使用 java 中的另一种方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13282587/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com