473,289 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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 6815
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

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

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.