I am not sure if I am doing this correctly since it has been awhile since I last used Daniweb. I need some help with the code that I have submitted and am getting the following two errors. I am new to java and not sure of what to do. Can someone please help me to get my code to compile and run as expected?
/*Program: MortgagePaymentCalculatorCR3.java
Purpose: To write a Java program (without GUI) for agents of McBride Financial
Services. This resource will calculate and display the payment expected
for 3 mortgage loans with the following terms and interest rates using
an array:
7 year @ 5.35%
15 year @ 5.5%
30 year @ 5.75%
The loan balance and interest paid for each payment over the duration of
each loan will also be displayed. Loops will display part of the list,
pause, and display more of the list to the agent.
*/
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class MortgageCalculatorExample
{
public static void main(String[] args)
{
//Define variables for array
double [] yearlyTerm = {7, 15, 30}; //mortgage term (total years)
double [] monthlyTerm = {84, 180, 360}; //mortgage terms (total months)
double [] apr = {.0535, .055, .0575}; //annual percentage rate
//Declare additional Variables
double principal; //loan amount
double paymentFormula; //factor to calculate monthly payment
double interestRate; //interest rate
double monthlyPayment; //monthly payment
int term; //variable part of notePeriod
int linecount; //to display lines
double monthlyInterest; //monthly interest
double monthlyPrincipal; //monthly principal
double loanBalance;
//initialize variables
principal = 200000; //loan amount
paymentFormula = 0; //initializes value for paymentFormula
interestRate = 0; //initializes value for interestRate
monthlyPayment = 0; //initializes value for monthlyPayment
loanBalance = principal;
//Loop for array
int i;
for (i = 0; i <= 2; i ++) {
//formula to calculate interest rate
interestRate = apr[i] / 12; //monthly interest rate
//formula to calculate paymentFormula
paymentFormula = (Math.pow((1 + interestRate), monthlyTerm[i]) -1)/
(interestRate * Math.pow((1 + interestRate), monthlyTerm[i]));
//formula to calculate the monthly payment
monthlyPayment = principal / paymentFormula;
//format numbers
NumberFormat formatter = new DecimalFormat("#0.00");
//output
System.out.println("Amount borrowed: $" + formatter.format(principal));
System.out.println("Mortgage term (years): " + yearlyTerm[i]);
System.out.println("Interest rate (percent): " + apr[i] * 100);
System.out.println("Monthly mortgage payment amount: $" + formatter.format(monthlyPayment));
System.out.println();
//format table
System.out.println("\nPayments Left\t Interest Paid\t Loan Balance");
System.out.println("-------------- -------------- --------------");
//while loop
while (monthlyTerm > 0) {
//data output for table
System.out.println(monthlyTerm + "\t\t$"
+ formatter.format(monthlyInterest)
+ "\t\t$" + formatter.format(loanBalance));
//Decrement term of mortgage loan
monthlyTerm++;
//declare monthly interest and principal and loan balance in while loop
monthlyInterest = loanBalance * interestRate;
monthlyPrincipal = monthlyPayment - monthlyInterest;
loanBalance = loanBalance - monthlyPrincipal;
//Pause output
if(linecount == 20) {
linecount = 0;
try {
Thread.sleep(2000);
}
catch (InterruptedException e) {
}
}
else {
linecount++;
}
}
}
}
}
C:\Users\Momma Bear\Documents\UOP\PRG420\Week 5\MortgageCalculatorExample.java:83: operator > cannot be applied to double[],int
while (monthlyTerm > 0) {
^
C:\Users\Momma Bear\Documents\UOP\PRG420\Week 5\MortgageCalculatorExample.java:90: operator ++ cannot be applied to double[]
monthlyTerm++;
^
2 errors
Thanks in advance.