|
|
| Subject: Mortgage Payment Calculator · Posted: 2006-10-05, 08:08am |
|
|
|
Rank: ? (9)
Member #: 28324
|
Hello!! I am hoping someone can help me figure out these errors during compiling. Below is my code, and any help is much appreciated!!
Code:
/*
- * MortgagecalculatorRev2.java
- *
- * Date: October 4, 2006
- * Version 2.0
- * Calculate and display the mortgage of the hard coded terms
- * amount = $200,000, the term = 30 years, and the interest rate = 5.75%
- * and list the loan balance and interest paid with hesitations to ensure
- * the list does not scroll off the screen.
- *
- * Author: Michelle Troy
- * Requestor: Haiyan Tian
- * Class: POS 406 - Computer Programming I
- */
-
-
- import java.text.DecimalFormat; // Declares the mortgage in decimal format
- import java.text.NumberFormat;
- import java.io.*;
- import java.math.*;
- import java.text.*;
- import java.util.Date; // Imports the date
-
- public class MortgagecalculatorRev2 // Declares the class
-
- {
- public static void main (String[] args) throws IOException;
-
- // Declare the constant variables
- double dPrincipal = 200000.00;
- double dInterest = 0.0575;
- double dMonthlyInterest = dInterest/12;
- int iYears = 30;
- DecimalFormat money = new DecimalFormat("$0.00"); // Displays mortgage in decimal format
- {
- // Displays the mortgage calculator
- Date currentDate = new Date(); // Date constructor
- System.out.println ("\t\tWelcome to Michelle's Mortgage Calculator");
- System.out.println ("\t\t" + currentDate);
- System.out.println();
- System.out.println ("\t\tThe loan amount is $200,000");
- System.out.println ("\t\tThe term of the loan is 30 years");
- System.out.println ("\t\tThe interest rate for the loan is 5.75%");
- System.out.println();
-
- do {
- System.out.println("\t\tPrincipal: " + (money.format(dPrincipal)));
-
- double value2 = MonthlyPayment (dPrincipal, dMonthlyInterest, iYears);
- double value3 = MonthlyPrincipal (value2, dMonthlyInterest);
- double dPrincipal = NewBalance (dPrincipal, value3);
- double value = CurrentMonthlyInterestPaid (dMonthlyInterest, dPrincipal);
- }
- while ((dPrincipal ! = 0) && (dPrincipal >= 0));
- }
- public static double CurrentMonthlyInterestPaid(double dMonthlyInterest, double dPrincipal)
- {
- // Declare and initialize variables and calculate the current monthly interest
- double dCurrentMonthlyInterestPaid = 0.0;
- dCurrentMonthlyInterestPaid = dPrincipal * dMonthlyInterest;
-
- System.out.println("\tMonthly Interest Paid: " + (money.format(dCurrentMonthlyInterestPaid)));
-
- return dCurrentMonthlyInterestPaid;
- }
- public static double MonthlyPayment (double dPrincipal, double dMonthlyInterest, int iYears)
- {
- double dMonthlyPayment = 0.0;
- dMonthlyPayment = (dPrincipal * dMonthlyInterest) / (1 - Math.pow(1 / (1 + dMonthlyInterest), iYears * 12));
- System.out.println ("\t\tMonthly Payment: " + (money.format(dMonthlyPayment)));
- return dMonthlyPayment;
-
- }
- public static double MonthlyPrincipal (double dMonthlyPayment, double dMonthlyInterest)
- {
- // Declare and intialize variables for the Monthly Principal
- double dMonthlyPrincipal = 0.0;
- dMonthlyPrincipal = (dMonthlyPayment - dMonthlyInterest);
-
- System.out.println("\tMonthly Principal: " + (money.format(dMonthlyPrincipal)));
-
- return dMonthlyPrincipal;
- }
- public static double NewBalance (double dPrincipal, double dMonthlyPrincipal)
- {
- // Calculate the New Balance
- double dNewBalance = 0.0;
- dNewBalance = dPrincipal - dMonthlyPrincipal;
-
- return dNewBalance;
- }
- }
|
|
|
| Subject: Re: Mortgage Payment Calculator · Posted: 2006-10-06, 02:38am |
|
|
|
Rank: ? (4821)
Member #: 3416
|
what errors do you get?
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
|
|
| Subject: Re: Mortgage Payment Calculator · Posted: 2006-10-06, 07:41am |
|
|
|
Rank: ? (9)
Member #: 28324
|
The errors are listed below: These are referencing Line 54:
C:\Documents and Settings\Michelle\Local Settings\Temporary Internet Files\Content.IE5\6RA3U5CF\MortgagecalculatorRev2.java:54: ')' expected
while ((dPrincipal ! = 0) && (dPrincipal >= 0));
^
C:\Documents and Settings\Michelle\Local Settings\Temporary Internet Files\Content.IE5\6RA3U5CF\MortgagecalculatorRev2.java:54: ')' expected
while ((dPrincipal ! = 0) && (dPrincipal >= 0));
^
2 errors
Tool completed with exit code 1
When I add the ')' in, it still gives the same errors.
Thanks!!
|
|
|
| Subject: Re: Mortgage Payment Calculator · Posted: 2006-10-06, 09:05am |
|
|
|
Rank: ? (9)
Member #: 28324
|
Ok, I made some major adjustments to my code, but now it is not calculating correctly...it is probably something I am just not
seeing.....but after looking at this for so long....my eyes are seeing things they shouldn't!!! Please help if you can!!
Code:
/*
- * MortgagecalculatorRev2.java
- *
- * Date: October 4, 2006
- * Version 2.0
- * Calculate and display the mortgage of the hard coded terms
- * amount = $200,000, the term = 30 years, and the interest rate = 5.75%
- * and list the loan balance and interest paid with hesitations to ensure
- * the list does not scroll off the screen.
- *
- * Author: Michelle Troy
- * Requestor: Haiyan Tian
- * Class: POS 406 - Computer Programming I
- */
-
- import java.text.DecimalFormat; // Declares the mortgage in decimal format
- import java.io.*;
- import java.math.*;
- import java.text.*;
- import java.util.Date; // Imports the date
-
- public class MortgagecalculatorRev2 // Declares the class
- {
-
- public static void main(String[] args) throws IOException
- {
- // Declares and builds the variables
- double loanAmount = 200000;
- int loanTerm = 360;
- double interest = .0575;
- double monthlyPayment = 0;
- DecimalFormat money = new DecimalFormat("$0.00"); // Displays mortgage in decimal format
-
-
- // Displays the mortgage calculator
- Date currentDate = new Date(); // Date constructor
- System.out.println("\t\tWelcome to Michelle's Mortgage Calculator");
- System.out.println("\t\t" + currentDate);
- System.out.println();
- System.out.println("\t\tThe loan amount is $200,000");
- System.out.println("\t\tThe term of the loan is 30 years");
- System.out.println("\t\tThe interest rate for the loan is 5.75%");
- System.out.println();
-
-
- // Declares formula used to calculate the loan amount
- monthlyPayment = (loanAmount*(interest/12))/(1 - 1 / Math.pow((1 + (interest/12)), loanTerm));
-
- System.out.println("\t\tThe monthly payment is: " + (money.format(monthlyPayment)));
- System.out.println();
-
- // Declares and builds new variables
- double loanBalance = 0;
- double interestPaid = 0;
- double principalPaid = 0;
- int lineCount = 20;
- interestPaid = loanAmount * interest;
- principalPaid = monthlyPayment - interestPaid;
- loanBalance = loanAmount - principalPaid;
-
-
- // Starts loop statement,and declares formula for loan balance and interest paid
- while (loanBalance >= 0) {
-
- // Displays the loan balance, principal paid, and interest paid
- System.out.println("The loan balance is: " + (money.format(loanBalance)));
- System.out.println("The interest paid on the loan is: " + (money.format(interestPaid)));
- System.out.println("The principal paid on the loan is: " + (money.format(principalPaid)));
-
-
-
- // Pauses screen
- if (lineCount > 0) {
- lineCount--;
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- }
- }
- }
- // Stops loop statement
- if (loanBalance <= 0) {
- System.out.println("The loan balance is: $0.00");
- }
-
- }
-
- }
|
|
|
| Subject: Re: Mortgage Payment Calculator · Posted: 2006-10-18, 09:27am |
|
|
|
Rank: ? (2)
Member #: 28855
|
Did u ever figure out why the calculation was incorrect on this program?
|
|
|
| Subject: Re: Mortgage Payment Calculator · Posted: 2006-10-20, 07:11am |
|
|
|
Rank: ? (134)
Member #: 28863
|
what exactly is not calculating correctly. Are you getting figures but wrong ones ??
|
|
|
| Subject: Re: Mortgage Payment Calculator · Posted: 2006-10-20, 08:27am |
|
|
|
Rank: ? (2)
Member #: 28855
|
yes, it is not calculating the correctly.
|