PDA

View Full Version : Java Code Help - Again


MacroGuru
08-22-2005, 04:17 PM
Can anyone take a look at my program and tell me where the fault is at?

I am supposed to generate Amortization for 3 different mortgages, and I am getting 2 errors I cannot figure out.

Thanks


/*
*POS/406
*Mortgage Application
*By Dennis Thomas
*/
import java.text.*;
import java.io.*;
public class Mortgage{

public static void main(String[] arguments){

//Define Mortgage Array
Mortgage[] arrMortgages = new mortgages[3];

//Define the objects in the array
arrMortgage[0] = new Mortgage(200,000, 30, .0575);
arrMortgage[1] = new Mortgage(200,000, 7, .0535);
arrMortgage[2] = new Mortgage(200,000, 15, .055);

double dPrincipal;
int iTerm;
double dRate;
double dnumPayments;
double dmonthlyPayment;
int iPeriods = 12;

// Loop rest of program through all 3 mortgages
for (int x=0; x<3; x++) {
// Display Loan Info before displaying Amoritization Table
DisplayInfo(mortgages[x], x);
Mortgage.pause();
// Display Amoritization Table for each loan
mortgages[x].DisplayAmoritization();
Mortgage.pause();

public Mortgage(double dPrincipal, int iTerm, double dRate){

dnumPayments = iTerm*iPeriods
dmonthlyPayment = this.MonthlyPayment
}

public void DisplayInfo(Mortgage m, int iNum){
//Display prefigured information to the end user
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println("\t\n Your Mortgage Amount is" + nf.format(dPrincipal));
System.out.println("\t\n Your Yearly Interest Rate is " + dRate);
System.out.println("\t\n Your Term years are " + iTerm);
m.MonthlyRate();
m.TotalMonths();
m.MonthlyPayment();
}

public double MonthlyRate(){
dMonthRate = dRate/(12 * 100);//figure out the Monthly Rate
System.out.println("\t\n Your Monthly Rate is " + dMonthRate);


}
public int TotalMonths(){
iMonthsTotal = iTerm*12;//figure out the total months of the loan
System.out.println("\t\n Your total months on the loan are " + iMonthsTotal);
}

public double MonthlyPayment(){
dmonthlyPayment = iAmount * ( (dMonthRate * Math.pow((1+dMonthRate),iMonthsTotal)) / (Math.pow((1+dMonthRate),iMonthsTotal) - 1) );//figure out the monthly payment
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println("\t\n Your Monthly Payment is " + nf.format(dPayment));
}
public void DisplayAmoritization(){
double dCurrentMonthlyInterest;
double dPaymentAmount;
double dPaymentBalance;
double dp = dPrinciple; // changeable principle variable for this function
double dMI = dRate/iPeriods; // monthly interest = interest/12
System.out.println("\t\tBalance\t\tMonthly Payment\t\tAmt Principle\t\tAmt Interest");
for (int x = 0; x < dnumPayments; x++) {
//pause every 15 lines
double numLines = 15.00;
int dummy = (int)x/15;
if (((x/numLines) == (double)dummy)&&(dummy != 0)) {
Mortgage.pause();
}
// figuring and outputting amortization stuff
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
dCurrentMonthlyInterest = dp * dMI;
dPaymentAount = dmonthlyPayment - dCurrentMonthlyInterest;
dPaymentBalance = dp - dPaymentAmount;
System.out.println((x+1) + "\t\t" + nf.format(dp) + "\t\t" + nf.format(dmonthlyPayment) + "\t\t\t" + nf.format(dPaymentAmount) + "\t\t\t" + nf.format(dCurrentMonthlyInterest));
dp = dPaymentBalance;
}
}
}
}
}

Surtt
08-22-2005, 04:29 PM
And the errors are?

MacroGuru
08-22-2005, 04:32 PM
I am getting an illegal start of expression with the Public Mortgage function declaration and a ';' expected at line 104, however, I can not see where it is at, but this is using JCreator IDE, so if someone is using another IDE that might give more information it would be helpful.

Thanks,

MikeVic
08-22-2005, 04:34 PM
You're missing two semi-colons on the function?

" dnumPayments = iTerm*iPeriods;
dmonthlyPayment = this.MonthlyPayment; "

MacroGuru
08-22-2005, 04:35 PM
You're missing two semi-colons on the function?

" dnumPayments = iTerm*iPeriods;
dmonthlyPayment = this.MonthlyPayment; "
I caught that, just as I posted this, I was also missing the () on the end of MonthlyPayment there as well...

MikeVic
08-22-2005, 04:36 PM
And you're main doesn't have a closing curly brace?

MacroGuru
08-22-2005, 04:37 PM
And you're main doesn't have a closing curly brace?It should on line 106....

Ignore this....I just found it and opened up a can of worms....

I will be back with new code.....

MikeVic
08-22-2005, 04:40 PM
Maybe I'm rusty, but can you have all of these methods inside of main?

MikeVic
08-22-2005, 04:41 PM
dola, I think you found what I was talking about then. :)

MacroGuru
08-22-2005, 06:34 PM
Mike,

thank you for pointing the things out you did, it actually helped me out a lot....I was able to finalize the code and get it working how it properly should.

Thank you!

MikeVic
08-22-2005, 06:50 PM
No problem.

sterlingice
08-22-2005, 06:55 PM
Dang, I keep missing out on these fairly easy Java threads. Be fun to solve some of those again :)

SI

Greyroofoo
08-22-2005, 07:05 PM
ahhhh, if only all my java problems were this easy

dacman
04-04-2008, 09:42 AM
There are several ways to do it.

1) Implement a method that sends a message to the other frames that a click happened in a different frame

2) Make all frames mouse listeners and re-cast the mouse actions to cause a mouse event to happen in every frame every time. (Ugly, and I personally wouldn't suggest it, but it's possible)

I'm sure there are other ways to do it -- but you will probably need a list of all instantiated frames, or possibly a unique higher level container to keep track of each frame.

cartman
04-04-2008, 03:52 PM
I'd like to point out that this is actual code, not macros.

:D