Welcome to Dream.In.Code
Become a Java Expert!

Join 149,485 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,345 people online right now. Registration is fast and FREE... Join Now!




Mortage calculator using array

 
Reply to this topicStart new topic

Mortage calculator using array, keep getting error code

hightemp01
18 Apr, 2007 - 12:02 PM
Post #1

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 3


My Contributions
/*G
Mortgage Calculator
04/07
*/




import java.text.NumberFormat;
import java.util.Locale;


public class Mortgage2
{
public static void main (String args[] ) //main function
{
//Declare variables
//Set interest, amount and number of years

double amount = 200000.00; // loan amount
double term[] = 30, 15, 7;
double rate[] = 5.75, 5.5, 5.35/100; // converts to percentage
for(icount=0; icount<4; icount++) // loops through
rate = rate/12;
NumberFormat moneyformat = NumberFormat.getCurrencyInstance (Locale.US);
double result = (amount=rate)/(1-Math.pow(1/(1+rate[1]),term * 12));
String strResult = moneyFormat.format(result);

//Print to screen

System.out.println("McBride Financial Services Mortgage Calculator");
System.out.println();
System.out.println("Principal:\t\t"+amount);
System.out.println("Interest rate:\t\t"+term);
System.out.println("Years:\t\t\t"+rate);}

}

User is offlineProfile CardPM
+Quote Post

Ellie
RE: Mortage Calculator Using Array
19 Apr, 2007 - 12:50 AM
Post #2

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions

To begin with, you are missing braces from your array declarations:

CODE
double term[] = {30, 15, 7};


I am not sure what you want to store in your next array:
CODE
double rate[] = {5.75, 5.5, 5.35/100}; // converts to percentage

Is that storing 3 different rates? Are they all supposed to be divided by 100 or just the last one?

You cannot do this:
CODE
rate = rate/12;

Because rate is an array, you would have to name the array item you wanted to divide by 12 i.e.
CODE
rate[icount] = rate[icount]/12;


I'm not really sure exactly what the program is for though, maybe you could post the question you've been set too?

Well, I hope that helps you a bit smile.gif


User is offlineProfile CardPM
+Quote Post

hightemp01
RE: Mortage Calculator Using Array
19 Apr, 2007 - 09:07 AM
Post #3

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 3


My Contributions
import java.text.NumberFormat;
import java.util.Locale;


public class Mortgage2
{
public static void main (String args[] ) //main function
{
//Declare variables
//Set interest, amount and number of years
{nrate = rate[icount]/12;
NumberFormat moneyformat = NumberFormat.getCurrencyInstance (Locale.US);
double result = (amount*rate)/(1-Math.pow(1/(1+term[icount]),term * 12));
String strResult = moneyFormat.format(result);
double amount = 200000.00; // loan amount
double term[] = {30, 15, 7};
double rate[] = {5.75, 5.5, 5.35}; // converts to percentage
for(icount=0; icount<4; icount++); // loops through

//Print to screen

System.out.println("McBride Financial Services Mortgage Calculator");
System.out.println();
System.out.println("Loan Amount:\t\t"+amount);
System.out.println("Interest rate:\t\t"+rate[icount]);
System.out.println("Years:\t\t\t"+term[icount]);}
{
}
I am trying to calculate the payment amount for 3 mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%

Use an array for the different loans. Display the mortgage payment amount for each loan.


User is offlineProfile CardPM
+Quote Post

Ellie
RE: Mortage Calculator Using Array
19 Apr, 2007 - 09:47 AM
Post #4

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions


OK, I've got what you have working, but you might need to check it's actually accurate rolleyes.gif

CODE
import java.text.NumberFormat;
import java.util.Locale;


public class Mortgage2
{
public static void main (String args[] ) //main function
{
//Declare variables
//Set interest, amount and number of years
double amount = 200000.00; // loan amount
double term[] = {30, 15, 7};
double rate[] = {5.75, 5.5, 5.35}; // converts to percentage
NumberFormat moneyformat = NumberFormat.getCurrencyInstance (Locale.US);




for(int icount=0; icount<3; icount++)// loops through
{ double nrate = rate[icount]/12;
double result = (amount*nrate)/(1-Math.pow(1/(1+term[icount]),term[icount] * 12));
String strResult = moneyformat.format(result);
//Print to screen


System.out.println("McBride Financial Services Mortgage Calculator");
System.out.println();
System.out.println("Loan Amount:\t\t"+amount);
System.out.println("Interest rate:\t\t"+nrate);
System.out.println("Years:\t\t\t"+term[icount]);
System.out.println("Payment:\t\t\t" + strResult);}

}
}

User is offlineProfile CardPM
+Quote Post

hightemp01
RE: Mortage Calculator Using Array
19 Apr, 2007 - 03:18 PM
Post #5

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 3


My Contributions
I am doing a tax calculator(without a GUI) and I dont even know where to start any help you can give will be very nice
User is offlineProfile CardPM
+Quote Post

Ellie
RE: Mortage Calculator Using Array
20 Apr, 2007 - 12:15 AM
Post #6

D.I.C Regular
Group Icon

Joined: 17 Jan, 2007
Posts: 427



Thanked: 4 times
Dream Kudos: 150
My Contributions

Well, if the tax calculation is similar to your mortgage calculator, you should be able to use the mortgage program that you have, and modify the numbers and calculation part to apply to your tax problem instead. Without knowing exactly what the question is, it's a bit difficult to advise you more than that, but basically it should work in the same way as your mortgage one.


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:50PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month