# Thread: Need help with another array

1. Member
Join Date
May 2011
Posts
47
Rep Power
0

## Need help with another array

Here is my original code for the application. I need this application to have an array for the different loans. I need to include 7, 15, and 30 as different loan terms for my variable loanTerm. I need to have .0535, .0550, and .0575 as the different interest rates for the variable intRates. Here is my original code.
Java Code:
```package mortgage;

/**The Mortgage class implements an application which calculates the mortgage
*payment, interest paid, principal paid and loan balance.
* The application prints interest paid, mortgage payment, and loan balance
* to output
* @author Lekeisha
**/
import java.io.IOException;
public class Mortgage
/**Creates a new instance of Mortgage**/
{
public static void main(String[] args)
{

int amLoanOne = 200000;//initial amount of loan
double monIntRate = 0.0;//initiates the monthly interest rate
double monPay = 0;//initiates the mortgage payment
monIntRate = .0575/12;//interest rate of 5.75%
double totMons = 30*12;//term of loan which is 30 years
double intsPaid = 0;//initiates interest paid
double princPaid = 0;//initiates principal paid
double amLoanNxt = 0;//initiates the amount of loan balance after initial amount

monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
//calculates the mortgage payment
intsPaid = amLoanOne*monIntRate;
//calculates the interest paid
princPaid = monPay - intsPaid;
//calculates the principal paid
amLoanNxt = amLoanOne - princPaid;
//calculates the amount of loan balance after initial amount

for(int i = 0; i < 31; i++)
{
intsPaid+=i;//counter for interest paid
princPaid+=i;//counter for principal paid
amLoanNxt+=i;//counter for amount of loan balance after initial amount

System.out.println("Interest amount is \$" + Math.round(intsPaid)+ ".");
//calculates the interest paid with interest rate of 5.75%
System.out.println("Mortgage payment amount is \$"  + Math.round(monPay)+ ".");
//calculates the mortgage payment amount
System.out.println("Loan balance amount is \$" + Math.round(amLoanNxt)+  ".");
//calculates the loan balance
System.out.println("(press Enter to exit)");
//asks user input of 'Enter' to display other lines of text
try
{
}
catch (IOException e)
{
return;

}
}
}
}```

2. Member
Join Date
May 2011
Posts
47
Rep Power
0
Here is my attempt at it. This is so confusing. Please provide any advice. Thanks.
package mortgages;
Java Code:
```/**The Mortgage class implements an application which calculates the mortgage
*payment, interest paid, principal paid and loan balance.
* The application prints interest paid, mortgage payment, and loan balance
* to output
* @author Lekeisha
**/
import java.io.IOException;
public class Mortgages
/**Creates a new instance of Mortgage**/
{

public static void main(String[] args)
{
double[]loanTerm = {7, 15, 30};
double[]intRates = {.0535, .0550, .0575};//initiates the monthly interest rate
calmonintrate(intRates);
caltotmons(loanTerm);
}
public static void calmonintrate(double intRates[])
{
for(int counter = 0; counter<intRates.length;counter++)
intRates[counter]/12;
}
public static void caltotmons(double loanTerm[])
{
for(int counter = 0; counter<loanTerm.length;counter++)
loanTerm[counter]*12;
}

monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
//calculates the mortgage payment
intsPaid = amLoanOne*monIntRate;
//calculates the interest paid

princPaid = monPay - intsPaid;
//calculates the principal paid
amLoanNxt = amLoanOne - princPaid;
//calculates the amount of loan balance after initial amount

for(int i = 0; i < 31; i++)
{
intsPaid+=i;//counter for interest paid
princPaid+=i;//counter for principal paid
amLoanNxt+=i;//counter for amount of loan balance after initial amount

System.out.println("Interest amount is \$" + Math.round(intsPaid)+ ".");
//calculates the interest paid with interest rate of 5.75%
System.out.println("Mortgage payment amount is \$"  + Math.round(monPay)+ ".");
//calculates the mortgage payment amount
System.out.println("Loan balance amount is \$" + Math.round(amLoanNxt)+  ".");
//calculates the loan balance
System.out.println("(press Enter to exit)");
//asks user input of 'Enter' to display other lines of text
try
{
}
catch (IOException e)
{
return;

}
}
}
}```

3. Can you explain what your problem is? Do you get errors?
If so please copy and paste here the FULL text of the error messages.

One possible problem I see is the scope of some of your variables. Many are local to the inside of the main method. That means no other method can see them unless they are passed as arguments. Move their definitions outside of the main method if you want other methods to be able to use them.

4. Member
Join Date
May 2011
Posts
47
Rep Power
0
Here is my error with running it.
Java Code:
```Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: calmonintrate
at mortgages.Mortgages.main(Mortgages.java:22)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)```

5. What kind of IDE are you using?
The error message mentions "Uncompilable source code" which makes me think the problem is when you try to compile the code, not execute it.

When I try to compile your code I get this:
Running: D:\Java\jdk1.6.0_02\bin\javac.exe -Xlint -g -deprecation -classpath D:\JavaDevelopment\;. Mortgages1.java

Mortgages1.java:22: not a statement
intRates[counter]/12;
^
Mortgages1.java:27: not a statement
loanTerm[counter]*12;
^
Mortgages1.java:31: <identifier> expected
monPay = amLoanOne*monIntRate/(1-(Math.pow((1+monIntRate), (-totMons))));
^
Mortgages1.java:33: <identifier> expected
intsPaid = amLoanOne*monIntRate;
^
Mortgages1.java:36: <identifier> expected
princPaid = monPay - intsPaid;
^
Mortgages1.java:38: <identifier> expected
amLoanNxt = amLoanOne - princPaid;
^
Mortgages1.java:43: illegal start of type
for(int i = 0; i < 31; i++)
^
Mortgages1.java:43: illegal start of type
for(int i = 0; i < 31; i++)
^
Mortgages1.java:43: <identifier> expected
for(int i = 0; i < 31; i++)
^
Mortgages1.java:68: class, interface, or enum expected
}
^
10 errors

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•