gpt4 book ai didi

java - 我找不到错误代码为 "Cannot find symbol"的原因

转载 作者:行者123 更新时间:2023-12-01 16:13:07 28 4
gpt4 key购买 nike

我试图弄清楚为什么当“monthlyPayment”位于我调用的方法的参数“interest_Total”内时找不到它(我在它旁边用两个星号标记它)。下面是我的代码,后面是错误。

import java.util.*;
public class TestCC
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);

System.out.println("Welcome to the payment calculator");
System.out.println("List of options");
System.out.println("MP: To calculate the Monthly Payment for a fix-rate, fix-term loan");
System.out.println("M: To calculat ethe number of Months to pay off a loan witha fixed monthly payment");

System.out.print("Please enter MP or M: ");
String choice = kb.next();

while (!(choice.equals("MP") || choice.equals("M")))
{
System.out.print("Error; Enter MP or M: ");
}

if (choice.equals("MP"))
{
// Loan Amount

System.out.print("Enter loan amount: ");
while (!kb.hasNextDouble())
{
kb.next();
System.out.print("Enter loan amount: ");
}
double loan = 0;
loan = kb.nextDouble();


// Term Amount

System.out.print("Enter term in years: ");
while (!kb.hasNextInt())
{
kb.next();
System.out.print("Enter term in years: ");
}
int years = 0;
years = kb.nextInt();


// Interest Rate

System.out.print("Enter the interest rate: ");
while (!kb.hasNextDouble())
{
kb.next();
System.out.print("Enter the interest rate: ");
}
double interestRate;
interestRate = kb.nextDouble();

// Calling methods Part 1
payment(loan, years, interestRate);

**interest_Total(monthlyPayment, years, loan);**

}
}
public static double payment(double loan, int years, double interestRate)

{
double monthlyPayment = 0;

monthlyPayment = (loan * (interestRate/12))/(1 - (1/(Math.pow((1 + (interestRate/12)),(years * 12)))));
System.out.printf("Monthly Payment: $%.2f", monthlyPayment);

return monthlyPayment;
}

public static double interest_Total(double monthlyPayment, int years, double loan)

{
double totalInterest2 = 0;
totalInterest2 = ((monthlyPayment * years * 12) - loan);
System.out.printf("Total Interest Paid: %.2f", totalInterest2);

return totalInterest2;
}
}

下面是我得到的错误

TestCC.java:63: error: cannot find symbol
interest_Total(monthlyPayment, years, loan);
^
symbol: variable monthlyPayment
location: class TestCC
1 error

最佳答案

monthlyPayment 是interest_Total 函数的参数名称。 MonthlyPayment 是付款函数中的变量。但是在您调用该函数的 main 中没有任何名称。也许这就是你的意思?

double monthlyPayment = payment(loan, years, interestRate);
interest_Total(monthlyPayment, years, loan);

关于java - 我找不到错误代码为 "Cannot find symbol"的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62482292/

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