ejuste
asked on
Mortgage Calculator
I'm having problem with this java code, can someone take a look at it and help me find what is wrong?
import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;
public class Mortgage
{
public static void main(String[] args);
{
Date currentDate = new Date();
//Date constructor
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
//declaring variables
final double PRINCIPAL = 200000;
final double INTEREST = .0575;
final double TERM = 12*30;
//declaring variables
final double MONTHLY = (((PRINCIPLE*(INTEREST/12) )/(1-Math (1+(INTEREST/12))-(TERM)))
//displaying variables
System.out.println("\t\t" + currentDate);
System.out.println("\t\tPr inciple or Loan Amount: " + PRINCIPLE);
System.out.println("\t\tIn terest Rate: " + INTEREST);
System.out.println("\t\tTh e Term of Loan (in months): " + TERM);
System.out.println("\t\tTh e Monthly Payment is: " + MONTHLY);
System.out.println(decimal Places.for mat(MONTHL Y));
}
}
import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;
public class Mortgage
{
public static void main(String[] args);
{
Date currentDate = new Date();
//Date constructor
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
//declaring variables
final double PRINCIPAL = 200000;
final double INTEREST = .0575;
final double TERM = 12*30;
//declaring variables
final double MONTHLY = (((PRINCIPLE*(INTEREST/12)
//displaying variables
System.out.println("\t\t" + currentDate);
System.out.println("\t\tPr
System.out.println("\t\tIn
System.out.println("\t\tTh
System.out.println("\t\tTh
System.out.println(decimal
}
}
You have to define the problem. If it doesn't compile, post the error. If it gives the wrong answer, state what's wrong.
ASKER
My problem is it does not compile. This is the error message I got.
A:\Mortgage Calculator.java:21: ')' expected
^
1 error
Tool completed with exit code 1
A:\Mortgage Calculator.java:21: ')' expected
^
1 error
Tool completed with exit code 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A few other problems as well...
Your spelling of PRINCIPAL is inconsistent... the definition is spelled PRINCIPAL and it's usage is spelled PRINCIPLE
There is no method called Math...
You're calculations don't work...
The following calculations should clean this up...
final double MONTHLY = (PRINCIPAL * (INTEREST/12)) + (PRINCIPAL / TERM);
Your spelling of PRINCIPAL is inconsistent... the definition is spelled PRINCIPAL and it's usage is spelled PRINCIPLE
There is no method called Math...
You're calculations don't work...
The following calculations should clean this up...
final double MONTHLY = (PRINCIPAL * (INTEREST/12)) + (PRINCIPAL / TERM);
ASKER
Thank you guys for your comments they help a lot.
I have a new problem that I would like someone to help me debug.
This the code, and this is the error message I got:
A:\Mortgage Calculator.java:16: class MortgageCalculator is public, should be declared in a file named MortgageCalculator.java
public class MortgageCalculator
^
1 error
Tool completed with exit code 1
-------------------------- ---------- ---------- ---------- ---------- ---------- ---
/*
Modify the mortgage program to display the mortgage payment amount.
Then, list the loan balance and interest paid for each payment over
the term of the loan. The list would scroll off the screen, but use loops to display
a partial list, hesitate, and then display more of the list. Do not use a graphical
user interface. Insert comments in the program to document the program.
*/
import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;
public class MortgageCalculator
{
public static void main(String[] args)
{
Date currentDate = new Date();
//Date constructor
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
//declaring variables
final double PRINCIPAL = 200000;
final double INTEREST = .0575;
final double TERM = 12*30;
//declaring variables
final double MONTHLY = (PRINCIPAL*(INTEREST/12))/ (1-Math.po w (1+INTEREST/12,-TERM));
//displaying variables
System.out.println("\t\t" + currentDate);
System.out.println("\t\tPr inciple or Loan Amount: " + PRINCIPAL);
System.out.println("\t\tIn terest Rate: " + INTEREST);
System.out.println("\t\tTh e Term of Loan (in months): " + TERM);
System.out.println("\t\tTh e Monthly Payment is: " + MONTHLY);
System.out.println(decimal Places.for mat(MONTHL Y));
double balance = PRINCIPAL;
// calculate monthly interest and principal
double monthlyInterest = (balance * (INTEREST/12));
double monthlyPrincipal = (MONTHLY - monthlyInterest);
// format column headers for results to be displayed
System.out.println("\n\nPa yment\tPri ncipal\t\t Interest\t \tBalance" );
System.out.println("------ ---\t----- ----\t---- -----\t--- ------");
int lines = 0;
for(int i=0; i<TERM; i++)
{
// information to display
System.out.println((i+1) + "\t\t" + decimalPlaces.format(month lyPrincipa l) +
"\t\t" + decimalPlaces.format(month lyInterest ) +
"\t\t" + decimalPlaces.format(balan ce));
// calculate interest and principal payments
monthlyInterest = (balance * (INTEREST/12));
monthlyPrincipal = (MONTHLY - monthlyInterest);
//reduce balance
balance -= monthlyPrincipal;
// pause every 25 lines
if(lines == 25)
{
lines = 0;
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}
else
{
lines++;
}
}
}
}
I have a new problem that I would like someone to help me debug.
This the code, and this is the error message I got:
A:\Mortgage Calculator.java:16: class MortgageCalculator is public, should be declared in a file named MortgageCalculator.java
public class MortgageCalculator
^
1 error
Tool completed with exit code 1
--------------------------
/*
Modify the mortgage program to display the mortgage payment amount.
Then, list the loan balance and interest paid for each payment over
the term of the loan. The list would scroll off the screen, but use loops to display
a partial list, hesitate, and then display more of the list. Do not use a graphical
user interface. Insert comments in the program to document the program.
*/
import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;
public class MortgageCalculator
{
public static void main(String[] args)
{
Date currentDate = new Date();
//Date constructor
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
//declaring variables
final double PRINCIPAL = 200000;
final double INTEREST = .0575;
final double TERM = 12*30;
//declaring variables
final double MONTHLY = (PRINCIPAL*(INTEREST/12))/
//displaying variables
System.out.println("\t\t" + currentDate);
System.out.println("\t\tPr
System.out.println("\t\tIn
System.out.println("\t\tTh
System.out.println("\t\tTh
System.out.println(decimal
double balance = PRINCIPAL;
// calculate monthly interest and principal
double monthlyInterest = (balance * (INTEREST/12));
double monthlyPrincipal = (MONTHLY - monthlyInterest);
// format column headers for results to be displayed
System.out.println("\n\nPa
System.out.println("------
int lines = 0;
for(int i=0; i<TERM; i++)
{
// information to display
System.out.println((i+1) + "\t\t" + decimalPlaces.format(month
"\t\t" + decimalPlaces.format(month
"\t\t" + decimalPlaces.format(balan
// calculate interest and principal payments
monthlyInterest = (balance * (INTEREST/12));
monthlyPrincipal = (MONTHLY - monthlyInterest);
//reduce balance
balance -= monthlyPrincipal;
// pause every 25 lines
if(lines == 25)
{
lines = 0;
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
}
}
else
{
lines++;
}
}
}
}
It looks like the name of the Java source file for this class is "Mortgage Calculator.java" instead of "MortgageCalculator.java" (note the space).
The name of the Java file must match exactly (including case) the name of the class contained within it.
The name of the Java file must match exactly (including case) the name of the class contained within it.
ASKER
Thanks Dean,
I tried to make the correction that you suggested, but this is the compile errors I have;
A:\Mortgage Calculator.java:24: '{' expected
public class Mortgage Calculator.java
^
A:\Mortgage Calculator.java:105: '}' expected
^
2 errors
Tool completed with exit code 1
I tried to make the correction that you suggested, but this is the compile errors I have;
A:\Mortgage Calculator.java:24: '{' expected
public class Mortgage Calculator.java
^
A:\Mortgage Calculator.java:105: '}' expected
^
2 errors
Tool completed with exit code 1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.