Hey all,
I have been working with this for about 4 days and pulling my hair out.

I can't figure out why I am getting the error messages in my code, when I compile.

Here is my code.

// Week3 Dwight Welsh
import java.text.DecimalFormat;

public class Mortgage
{
public static void main(String args[]) throws Exception
{
// declare and construct variables
	double  loanAmt = 200000; // principal loan amount
	double  loanTerm = 360; // loan term for 30 years
	double  loanYears = 30; // indicates the loan term in years
	double  intRate = 5.75; // interest rate 30 years
	double newIntRate; // displays interest rate calculation
	double monthlyPay = 0; // displays monthly payment calculation
DecimalFormat money = new DecimalFormat("$0.00"); // displays mortgage in decimal format
DecimalFormat money2 = new DecimalFormat("0.00%"); // displays interest rate in decimal format

// displays messages to indicate purpose of program and conditions in the console window
	System.out.println();
	System.out.println("Welcome to the Mortgage Payment Calculator");
	System.out.println();
	System.out.println("This program will calculate the mortgage payments for a $" + loanAmt);
	System.out.println("with the following loan terms and interest rates: 30 years @ 5.75%");
	System.out.println();
	System.out.println("The results are as follows:");


{

intRate = (intRate /12 * .01);
monthlyPay = loanAmt * intRate / (1 - Math.pow(1 + intRate, - loanTerm));

// displays results for loan in the console window
	System.out.println();
	System.out.println("The mortgage payment for a $" + loanAmt + " loan for " + (loanTerm /12) + " years at");
	System.out.println("a " + (money2.format(intRate) + " interest rate = " + (money.format(monthlyPay))));

//loan <-- calculate loan

	for (i) //<-- 1 through loan duration,
	incrementing (i) //<-- i + 1 on each iteration)

      (loan <-- loan - monthlyPayment)

      System.out.println("Monthly payment" + i + ":" + monthlyPayment);

(end for)
}
}
}

and here are the error messages
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:40: not a statement
for (i) //<-- 1 through loan duration,
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:40: ';' expected
for (i) //<-- 1 through loan duration,
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:40: ';' expected
for (i) //<-- 1 through loan duration,
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:41: not a statement
incrementing (i) //<-- i + 1 on each iteration)
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:43: ')' expected
(loan <-- loan - monthlyPayment)
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:47: ')' expected
(end for)
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:47: not a statement
(end for)
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:47: illegal start of expression
(end for)
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:47: ';' expected
(end for)
^
O:\college stuff\PRG420 JAVA PROGRAMMING I\Ind Assign\Wk3\Mortgage.java:50: reached end of file while parsing
}
^
10 errors

Tool completed with exit code 1


Thanks for any help.

IKE

try coding it this way

for (int i = 0; i < loanDuration; i++) {
loan = loan - monthlypayment

System.out.println(loan);
}

Hey Eric,

I had to make a few text edits, but I got it working.
Now I have a couple of other issues.

First of all it scrolls WAY too fast. I think I need to put in a loop so it will show part of the list, pause, then show more of the list. How do you add a loop to the code?

Secondly after it gets halfway throug the nmbers start becoming negative. I need to figure out how to start the first payment subtracting from the total of all loan payments including interest for the loan. I know the total of all payments will be 420,172.46. I need it to show the payment ammount, the balance of the loan and interest paid for each payment.

I know this part of the code was just a beginning point I had figured out, but I am still way over my head here.

Here is the working code:

// Week3 Dwight Welsh
import java.text.DecimalFormat;

public class Mortgage
{
public static void main(String args[]) throws Exception
{
// declare and construct variables
	double  loanAmt = 200000; // principal loan amount
	double  loanTerm = 360; // loan term for 30 years
	double  loanYears = 30; // indicates the loan term in years
	double  intRate = 5.75; // interest rate 30 years
	double newIntRate; // displays interest rate calculation
	double monthlyPay = 0; // displays monthly payment calculation
DecimalFormat money = new DecimalFormat("$0.00"); // displays mortgage in decimal format
DecimalFormat money2 = new DecimalFormat("0.00%"); // displays interest rate in decimal format

// displays messages to indicate purpose of program and conditions in the console window
	System.out.println();
	System.out.println("Welcome to the Mortgage Payment Calculator");
	System.out.println();
	System.out.println("This program will calculate the mortgage payments for a $" + loanAmt);
	System.out.println("with the following loan terms and interest rates: 30 years @ 5.75%");
	System.out.println();
	System.out.println("The results are as follows:");


{

intRate = (intRate /12 * .01);
monthlyPay = loanAmt * intRate / (1 - Math.pow(1 + intRate, - loanTerm));

// displays results for loan in the console window
	System.out.println();
	System.out.println("The mortgage payment for a $" + loanAmt + " loan for " + (loanTerm /12) + " years at");
	System.out.println("a " + (money2.format(intRate) + " interest rate = " + (money.format(monthlyPay))));

//loan <-- calculate loan

	for (int i = 0; i < loanTerm; i++) 	{
		loanAmt = loanAmt - monthlyPay;
	System.out.println(loanAmt);
	}
}
}
}

Thanks in advance.

IKE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.