468,738 Members | 2,392 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

Array-Mortgage Calculator

This is not a class project.The program below is to display mortgage interest paid for each payment over the term of the loan and loan balance.It is program using array. However, I am receiving the following error message:

--------------------Configuration: <Default>--------------------
C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\mortgageloan\src\ mortgageloan.java:30: operator > cannot be applied to double[],int
while(balance >0)

C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\mortgageloan\src\ mortgageloan.java:33: operator * cannot be applied to double[],double[]
interest = discountfactor * balance;
^
C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\mortgageloan\src\ mortgageloan.java:34: operator - cannot be applied to double[],double
principal = monthlypayment - interest;
^
C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\mortgageloan\src\ mortgageloan.java:37: mortgagecalculator is already defined in amortize(double[],double[],double[],double[])
double [] mortgagecalculator = {200000,5.75,360,5.35,84,5.5,180};
^
C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\mortgageloan\src\ mortgageloan.java:61: cannot find symbol
symbol : method formqt(double)
location: class java.text.DecimalFormat
twoDigits.formqt(principal) + " \t\t\t " + twoDigits.format(interest)
^
C:\Program Files\Xinox Software\JCreatorV4LE\MyProjects\mortgageloan\src\ mortgageloan.java:66: operator - cannot be applied to double[],double
balance = balance - principal;// change the balance minus principal



Source code used to generate the 6 errors.

/**
* @(#)mortgageloan.java
*
* mortgageloan application
*
* @author
* @version 1.00 2006/12/8
*/




import java.math.*;//*loan calculator
import java.text.*;//*formats numbers
public class mortgageloan {

public static void amortize(double[] mortgagecalculator,double[] monthlypayment,
double[] balance, double[] discountfactor)
{

// Format for Output
DecimalFormat twoDigits = new DecimalFormat("$###,###.00");
// declare


double principal;
int num = 1;
double interest;

while(balance >0)
{
// calculate interest a it changes
interest = discountfactor * balance;
principal = monthlypayment - interest;

//array for mortgage information
double [] mortgagecalculator = {200000,5.75,360,5.35,84,5.5,180};

//Output declare new variable new java.text
java.text.DecimalFormat dfm = new java.text.DecimalFormat(",###.00");

// statment to format output
if(num <0)
{
System.out.println("\t\t\t\t" + num + ".\t\t\t\t" +
twoDigits.format(principal) + " \t\t\t " + twoDigits.format(interest) + "\t\t\t\t" + twoDigits.format(balance));
}
else if (num >=10 && num < 100)
{
System.out.println("\t\t\t " + num + ".\t\t\t\t" +
twoDigits.format(principal) + " \t\t\t " + twoDigits.format(interest) + "\t\t\t\t" + twoDigits.format(balance));
}
else if (num > 100 && num < 360)
{
System.out.println("\t\t\t " + num + ".\t\t\t\t" +
twoDigits.format(principal) + "\t\t\t" + twoDigits.format(interest) + "\t\t\t\t" + twoDigits.format(balance));
}
else
{
System.out.println("\t\t\t " + num + ".\t\t\t\t" +
twoDigits.formqt(principal) + " \t\t\t " + twoDigits.format(interest)
+ "\t\t\t "+ twoDigits.format(balance));
}
++num; //increments the variable num by 1.

balance = balance - principal;// change the balance minus principal
}
}










public static void main (String[] args){

// declare
double discountfactor;// Variable for interest
double monthlypayment; //Variable fo monthly payment


//array for mortgage information
double [] mortgagecalculator = {200000,5.75,360,5.35,84,5.5,180};

//Output declare new variable new java.text
java.text.DecimalFormat dfm = new java.text.DecimalFormat(",###.00");


//Discount factor calculator and payments for the three loans

discountfactor =(1+ (( mortgagecalculator[1]/100)/12));//discountfactor for 30year at 5.75
monthlypayment = mortgagecalculator[0] * ((discountfactor - 1) / (1 - Math.pow(discountfactor, - mortgagecalculator[2])));//calauclate mortgage for 30yeara at 5.75
System.out.println("Your monthly payment on the 30 year loan is $" + dfm.format(monthlypayment));

discountfactor = (1 + ((mortgagecalculator[3] /100)/12));//discountfactor for 7 year at 5.35
monthlypayment = mortgagecalculator[0] *((discountfactor - 1) / (1 - Math.pow(discountfactor, - mortgagecalculator[4]))); //calculate mortgage for 7 year at 5.35
System.out.println("Your monthly payment on the 7 year at 5.35 is $" + dfm.format(monthlypayment));

discountfactor = (1 + ((mortgagecalculator[5]/100)/12));//discountfactor for 15 year at 5.5
monthlypayment = mortgagecalculator[0] * ((discountfactor - 1) /(1 - Math.pow(discountfactor, - mortgagecalculator[6])));//calculate mortgage for 15 year at 5.5
System.out.println("Your monthly payment on the 15 year at 5.5 is $" + dfm.format(monthlypayment));









}

}
Dec 29 '06 #1
1 6600
bartonc
6,596 Expert 4TB
I see that you had gotten help when you were working on this in Java.
Please read the posting guidelines (on the right while you are posting) to learn what CODE tags look like:
Expand|Select|Wrap|Line Numbers
  1. code should look like this
and try posting in the C++/C forum for help with this. Thanks.
Dec 31 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Brian | last post: by
2 posts views Thread by Stormkid | last post: by
8 posts views Thread by vcardillo | last post: by
12 posts views Thread by Sam Collett | last post: by
8 posts views Thread by Mike S. Nowostawsky | last post: by
104 posts views Thread by Leszek | last post: by
7 posts views Thread by Jim Carlock | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.