Hello,
I am doing a homework assignment and I am getting an "illegal character" error and I don't understand. The assignment is to use an array to calculate three mortgage payments based on three differnt rates and terms in years.

``````/* calculator program to fully amortize a 200k loan over 30 years ata rate of 5.75%
Created by: Andrew Johnson
Class: PGR420
Date: 07/23/2010
Purpose: This project displays the amortized monthly payment for loans below:
\$200,000.00 loan over a 7 year term at 5.35 interest
\$200,000.00 loan over a 15 year term at 5.5 interest
\$200,000.00 loan over a 30 year term at 5.75 interest
*/

import static java.lang.Math.*;
import java.util.Date;
import java.awt.*;
import java.applet.*;

public class MortCalcWk5
{
public static void main(String[] args)
{
//Define variables and initialize them

int[] term = { 7, 15, 30 };//length of loan in years
double[] rate = { 5.35, 5.5, 5.75 }; //rate of the loan
for(int i = 0; i < term.length; i++) {
for(double j = 0; j < rate.length; j++)

double P = 200000.0; //principal, initial amount of loan
double I = rate[j]; //interest rate
double L = term[i];	//Length-time in years to pay the loan off

//define more variable to simplify
double J = I/(12*100); //monthly interest rate in decimal form
double N = L*12; // number of months which the loan is amortized

//define monthly payment variable
double M = P*(J/(1-pow((1+J), -N))); //\$ amount of monthly payment

//display monthly payment
System.out.println("your monthly payment of the loan is");
System.out.println("\$ " +round(M*100.00)/100.00);

}

}
}``````

getting an "illegal character" error

Please copy and paste error text here.

The following is the error that I get.
Thanks
Drewdizzle

C:\Users\Andrew\Documents\PRG420\MortWk5.java:26: illegal character: \29

^
1 error

Tool completed with exit code 1

Did you intensionally not post anything?
Or is it invisible?

Your second for loop has no curly braces.

Is it a compile-time error?

Did you intensionally not post anything?
Or is it invisible?

I thought I posted the error. Did you try compiling it? Anyway, I got other errors now.

``````/* calculator program to fully amortize a 200k loan over 30 years ata rate of 5.75%
Created by: Andrew Johnson
Class: PGR420
Date: 07/23/2010
Purpose: This project displays the amortized monthly payment for loans below:
\$200,000.00 loan over a 7 year term at 5.35 interest
\$200,000.00 loan over a 15 year term at 5.5 interest
\$200,000.00 loan over a 30 year term at 5.75 interest
*/

import static java.lang.Math.*;
import java.util.Date;
import java.awt.*;
import java.applet.*;

public class MrtgageCalcWk5
{
public static void main(String[] args)
{
//Define variables and initialize them

int[] term = { 7, 15, 30 };//length of loan in years
double[] rate = { 5.35, 5.5, 5.75 }; //rate of the loan
for(int i = 0; i < term.length; i++) {
//for(int j = 0; j < rate[i].length; i++) {

double P = 200000.0; //principal, initial amount of loan
double I = rate; //interest rate
double L = term;	//Length-time in years to pay the loan off

//define more variable to simplify
double J = I/(12*100); //monthly interest rate in decimal form
double N = L*12; // number of months which the loan is amortized

//define monthly payment variable
double M = P*(J/(1-pow((1+J), -N))); //\$ amount of monthly payment

//display monthly payment
//System.out.println("your monthly payment of the loan is");
System.out.println("The monthly payment for a \$200,000.00 loan over a " + L + " year term at " + I + "% interest is:");
System.out.println("\$ " +round(M*100.00)/100.00);

}

//}

}
}``````

ERROR

``````C:\Users\Andrew\Documents\PRG420\MrtgageCalcWk5.java:28: incompatible types
found   : double[]
required: double
double I = rate; //interest rate
^
C:\Users\Andrew\Documents\PRG420\MrtgageCalcWk5.java:29: incompatible types
found   : int[]
required: double
double L = term;	//Length-time in years to pay the loan off
^
2 errors

Tool completed with exit code 1``````

Thanks

The compiler wants the same data types on both sides of an assignment statement.
It's telling you that one side is a double and the other side is a double[].

If you want to get an element out of an array use the array notation: [index]
double I = rate[index]; // get value at index

Thanks NormR1. I want to access all three values in the array. The output should give me three sentences. 1. The monthly payment for a 200,000 loan for 5 years at 5.35% is \$???. 2. the payment for a 200,000 loan for 7 years is \$???.0

I can put a '0' in the index such as I=rate[0]; but I will get three calculations of the first aray. I want all three of them.
Thanks again

Sounds like you need a loop with an index that varies and points to each element of the array in turn.

Sounds like you need a loop with an index that varies and points to each element of the array in turn.

Thanks NormR1,
All I needed to do was put the 'i' in the variable I = rate.

Thanks but don't worry, I'll be back with more Java problems.

Drewdizzle

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.