Solved

# array

Posted on 2006-04-27
176 Views
My compiler is saying a ) is missing on my equation.it appears to be there. is something wrong?

import java.io.*;
import java.text.DecimalFormat;

class MortgageWeek4
{

public static void main(String arguments[])
{
/*Declaring Program Variables*/
double interestRate = 0.0575;//*Interest rate
double principal = 200000.00;//*Amount of Loan
double monthlyInterest = interestRate/12; //*Monthly interest
int periods = 360; //* 30 yrs @12 months each year is 360 months
double balance = principal;
double monthlyPrincipal;
DecimalFormat df = new DecimalFormat("\$#,###.00");
//Create new decimal format object that has the format required for this program
double mortgageRate[] = {.0535,.0550,.0575};
int payments[] = {84,180,360};

double mortgage=(principal*(mortgageRate[i]/12)/(1-(Math.pow(1/(1+mortgageRate[i]/12)),(payments[i]*12))));

int lines = 0;

for(int i=0; i < 3; i++) {

System.out.println((i+1) + "\t\t\t" + df.format(mortgageRate[i]) +
"\t\t" + df.format(payments[i]) +
"\t\t" + df.format(mortgage));

}
}
}
0
Question by:pgmtkl

LVL 92

Accepted Solution

try:

class MortgageWeek4
{

public static void main(String arguments[])
{
/*Declaring Program Variables*/
double interestRate = 0.0575;//*Interest rate
double principal = 200000.00;//*Amount of Loan
double monthlyInterest = interestRate/12; //*Monthly interest
int periods = 360; //* 30 yrs @12 months each year is 360 months
double balance = principal;
double monthlyPrincipal;
DecimalFormat df = new DecimalFormat("\$#,###.00");
//Create new decimal format object that has the format required for this program
double mortgageRate[] = {.0535,.0550,.0575};
int payments[] = {84,180,360};

int lines = 0;

for(int i=0; i < 3; i++) {

double mortgage=(principal*(mortgageRate[i]/12)/(1-(Math.pow(1/(1+mortgageRate[i]/12), (payments[i]*12)))));
System.out.println((i+1) + "\t\t\t" + df.format(mortgageRate[i]) +
"\t\t" + df.format(payments[i]) +
"\t\t" + df.format(mortgage));

}
}
}
0

Author Comment

Thank you. that works. The mortgage rate is correct, displaying as .0535. Is there a way i could displaying it as 5.35%?
0

LVL 92

Expert Comment

try:

NumberFormat.getPercentInstance().format(mortgageRate[i])
0

Author Comment

Thank you.
0

## Featured Post

### Suggested Solutions

seriesUp challenge 7 81
Connect to IP Camera using Java 4 62
wordsFront challenge 8 48
copyEndy  challenge 15 40
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.