I'm trying to figure out why "monthlyPayment" cannot be found when it is within the parameter of the method I called, which is "interest_Total" (I marked it with two asterisks next to it). Below is my code, followed by the error.
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;
}
}
Below is the error I get
TestCC.java:63: error: cannot find symbol
interest_Total(monthlyPayment, years, loan);
^
symbol: variable monthlyPayment
location: class TestCC
1 error