Free2Code
 
Time: 2010-09-02, 01:38pm
Mortgage Payment Calculator
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:
  1. /*
  2. * MortgagecalculatorRev2.java
  3. *
  4. * Date: October 4, 2006
  5. * Version 2.0
  6. * Calculate and display the mortgage of the hard coded terms
  7. * amount = $200,000, the term = 30 years, and the interest rate = 5.75%
  8. * and list the loan balance and interest paid with hesitations to ensure
  9. * the list does not scroll off the screen.
  10. *
  11. * Author: Michelle Troy
  12. * Requestor:  Haiyan Tian
  13. * Class:  POS 406 - Computer Programming I
  14. */
  15. import java.text.DecimalFormat; // Declares the mortgage in decimal format
  16. import java.text.NumberFormat;
  17. import java.io.*;
  18. import java.math.*;
  19. import java.text.*;
  20. import java.util.Date; // Imports the date
  21. public class MortgagecalculatorRev2 // Declares the class
  22. {
  23.     public static void main (String[] args) throws IOException;
  24.     // Declare the constant variables
  25.     double dPrincipal = 200000.00;
  26.     double dInterest = 0.0575;
  27.     double dMonthlyInterest = dInterest/12;
  28.     int iYears = 30;
  29.     DecimalFormat money = new DecimalFormat("$0.00"); // Displays mortgage in decimal format
  30. {
  31.     // Displays the mortgage calculator
  32.     Date currentDate = new Date(); // Date constructor
  33.     System.out.println ("\t\tWelcome to Michelle's Mortgage Calculator");
  34.     System.out.println ("\t\t" + currentDate);
  35.     System.out.println();
  36.     System.out.println ("\t\tThe loan amount is $200,000");
  37.     System.out.println ("\t\tThe term of the loan is 30 years");
  38.     System.out.println ("\t\tThe interest rate for the loan is 5.75%");
  39. System.out.println();
  40. do {
  41.     System.out.println("\t\tPrincipal: " + (money.format(dPrincipal)));
  42.     double value2 = MonthlyPayment (dPrincipal, dMonthlyInterest, iYears);
  43.     double value3 = MonthlyPrincipal (value2, dMonthlyInterest);
  44.     double dPrincipal = NewBalance (dPrincipal, value3);
  45.     double value = CurrentMonthlyInterestPaid (dMonthlyInterest, dPrincipal);
  46. }
  47. while ((dPrincipal ! = 0) && (dPrincipal >= 0));
  48. }
  49. public static double CurrentMonthlyInterestPaid(double dMonthlyInterest, double dPrincipal)
  50. {
  51.     // Declare and initialize variables and calculate the current monthly interest
  52.     double dCurrentMonthlyInterestPaid = 0.0;
  53.     dCurrentMonthlyInterestPaid = dPrincipal * dMonthlyInterest;
  54.     System.out.println("\tMonthly Interest Paid: " + (money.format(dCurrentMonthlyInterestPaid)));
  55.     return dCurrentMonthlyInterestPaid;
  56. }
  57. public static double MonthlyPayment (double dPrincipal, double dMonthlyInterest, int iYears)
  58. {
  59.     double dMonthlyPayment = 0.0;
  60.     dMonthlyPayment = (dPrincipal * dMonthlyInterest) / (1 - Math.pow(1 / (1 + dMonthlyInterest), iYears * 12));
  61.     System.out.println ("\t\tMonthly Payment: " + (money.format(dMonthlyPayment)));
  62.     return dMonthlyPayment;
  63. }
  64. public static double MonthlyPrincipal (double dMonthlyPayment, double dMonthlyInterest)
  65. {
  66.     // Declare and intialize variables for the Monthly Principal
  67.     double dMonthlyPrincipal = 0.0;
  68.     dMonthlyPrincipal = (dMonthlyPayment - dMonthlyInterest);
  69.     System.out.println("\tMonthly Principal: " + (money.format(dMonthlyPrincipal)));
  70.     return dMonthlyPrincipal;
  71. }
  72. public static double NewBalance (double dPrincipal, double dMonthlyPrincipal)
  73. {
  74.     // Calculate the New Balance
  75.     double dNewBalance = 0.0;
  76.     dNewBalance = dPrincipal - dMonthlyPrincipal;
  77.     return dNewBalance;
  78. }
  79. }


 
  Reply to this ·  Post link ·  Top
Subject: Re: Mortgage Payment Calculator  ·  Posted: 2006-10-06, 02:38am
Rank: ? (4824)
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
 
  Reply to this ·  Post link ·  Top
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!!

 
  Reply to this ·  Post link ·  Top
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:
  1. /*
  2. * MortgagecalculatorRev2.java
  3. *
  4. * Date: October 4, 2006
  5. * Version 2.0
  6. * Calculate and display the mortgage of the hard coded terms
  7. * amount = $200,000, the term = 30 years, and the interest rate = 5.75%
  8. * and list the loan balance and interest paid with hesitations to ensure
  9. * the list does not scroll off the screen.
  10. *
  11. * Author: Michelle Troy
  12. * Requestor:  Haiyan Tian
  13. * Class:  POS 406 - Computer Programming I
  14. */
  15. import java.text.DecimalFormat; // Declares the mortgage in decimal format
  16. import java.io.*;
  17. import java.math.*;
  18. import java.text.*;
  19. import java.util.Date; // Imports the date
  20. public class MortgagecalculatorRev2 // Declares the class
  21. {
  22. public static void main(String[] args) throws IOException
  23. {
  24. // Declares and builds the variables
  25. double loanAmount = 200000;
  26. int loanTerm = 360;
  27. double interest = .0575;
  28. double monthlyPayment = 0;
  29. DecimalFormat money = new DecimalFormat("$0.00"); // Displays mortgage in decimal format
  30. // Displays the mortgage calculator
  31. Date currentDate = new Date(); // Date constructor
  32. System.out.println("\t\tWelcome to Michelle's Mortgage Calculator");
  33. System.out.println("\t\t" + currentDate);
  34. System.out.println();
  35. System.out.println("\t\tThe loan amount is $200,000");
  36. System.out.println("\t\tThe term of the loan is 30 years");
  37. System.out.println("\t\tThe interest rate for the loan is 5.75%");
  38. System.out.println();
  39. // Declares formula used to calculate the loan amount
  40. monthlyPayment = (loanAmount*(interest/12))/(1 - 1 / Math.pow((1 + (interest/12)), loanTerm));
  41. System.out.println("\t\tThe monthly payment is: " + (money.format(monthlyPayment)));
  42. System.out.println();
  43. // Declares and builds new variables
  44. double loanBalance = 0;
  45. double interestPaid = 0;
  46. double principalPaid = 0;
  47. int lineCount = 20;
  48. interestPaid = loanAmount * interest;
  49. principalPaid = monthlyPayment - interestPaid;
  50. loanBalance = loanAmount - principalPaid;
  51. // Starts loop statement,and declares formula for loan balance and interest paid
  52. while (loanBalance >= 0) {
  53. // Displays the loan balance, principal paid, and interest paid
  54. System.out.println("The loan balance is: " + (money.format(loanBalance)));
  55. System.out.println("The interest paid on the loan is: " + (money.format(interestPaid)));
  56. System.out.println("The principal paid on the loan is: " + (money.format(principalPaid)));
  57. // Pauses screen
  58. if (lineCount > 0) {
  59. lineCount--;
  60. try {
  61. Thread.sleep(2000);
  62. } catch (InterruptedException e) {
  63. }
  64. }
  65. }
  66. // Stops loop statement
  67. if (loanBalance <= 0) {
  68. System.out.println("The loan balance is: $0.00");
  69. }
  70.     }
  71. }


 
  Reply to this ·  Post link ·  Top
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?

 
  Reply to this ·  Post link ·  Top
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 ??




 
  Reply to this ·  Post link ·  Top
Subject: Re: Mortgage Payment Calculator  ·  Posted: 2006-10-20, 08:27am
Rank: ? (2)
Member #: 28855
yes, it is not calculating the correctly.



 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

Penguino AVR

Want to learn about robotics or microcontrollers?
Check out the Penguino AVR from our friends at
Icy Labs