943,095 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 965
  • Java RSS
Feb 7th, 2010
0

mortgage calculator help

Expand Post »
The Mortgage Calculator will calculate and displays the mortgage payment amount given the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage.

The user will be asked to enter to the amount of the mortgage loan, the term in years of the mortgage, and an annual interest rate. The amount of the mortgage loan shall be greater than 0 and not exceed 10,000,000 dollars. The minimum term for the loan is five years, with a maximum of 30 years. In addition to the user being able to supply the mortgage information the application will display three of the most commonly used mortgages and the user shall be able to select these mortgages instead of supplying the mortgage information. Once the user has provided the mortgage information, the program shall calculate the monthly mortgage payment and the amortization table for the life of the mortgage. For each month the amortization table shall display the loan period, loan balance, principal balance, interest balance, principal paid and interest paid.

Main Class that contains the main method and any supporting utility methods. The Main class will not process any mortgage or amortization table information
User input class that collects and validated user input
Class that only holds the user provided information
Mortgage information processing and formatting
Amortization table processing and formatting
Display class to present the output Program Title
Program Description
Input/Output Analysis
Class/Object Table
Class Method Pseudocode this is what iam have done so far looking for help how to finish it


Java Syntax (Toggle Plain Text)
  1. /**
  2.  * A class that provides some primitive formating capabilities:
  3.  * allows strings to be left or right justified within some
  4.  * specified field width (fill character may also be specified).
  5.  * Author: Jake Foster
  6.  */
  7. public class Justify
  8. {
  9.  
  10.  
  11. /**
  12.   * Right justify a string, padding with spaces.
  13.   *
  14.   * @param s the string to justify
  15.   * @param width the field width to justify within
  16.   *
  17.   * @return the justified string.
  18.   */
  19. public static String right(String s, int width)
  20. {
  21. return right(s, width, ' ');
  22. }
  23.  
  24. public static String right(String s, int width, char fillChar)
  25. {
  26. if (s.length() >= width)
  27. return s;
  28. StringBuffer sb = new StringBuffer(width);
  29. for (int i = width - s.length(); --i >= 0; )
  30. sb.append(fillChar);
  31. sb.append(s);
  32. return sb.toString();
  33. }
  34.  
  35. }

Java Syntax (Toggle Plain Text)
  1.  
  2. /********************************************************************
  3. Program Name: Mortgage Calcuator.AmortizationData
  4. Programmers Name: Jake Foster
  5.  
  6.  
  7. Program Description:
  8. Data structure to hold amortization data for the Amortization table
  9.  
  10. Limitations: Data retrieval should be incorporated with
  11. get properties and data validation should be incorporated.
  12.  
  13. ********************************************************************/
  14. public class AmoritizationData
  15. {
  16. public double loanBalance;
  17. public double principalBalance;
  18. public double interestBalance;
  19. public double principalPaid;
  20. public double interestPaid;
  21. public int period;
  22.  
  23. public AmoritizationData(int period,
  24. double loanBalance,
  25. double principalBalance,
  26. double interestBalance,
  27. double principalPaid,
  28. double interestPaid)
  29. {
  30. this.period = period;
  31. this.loanBalance = loanBalance;
  32. this.principalBalance = principalBalance;
  33. this.interestBalance = interestBalance;
  34. this.principalPaid = principalPaid;
  35. this.interestPaid = interestPaid;
  36. }
  37. }

Java Syntax (Toggle Plain Text)
  1.  
  2. /********************************************************************
  3. Program Name: Mortgage Calcuator.Mortgage Amortization Information
  4. Programmers Name: Jake Foster
  5.  
  6. Program Description:
  7. This class holds loan amortization information for an specific mortgage
  8. loan, apr, term, and payment.
  9.  
  10. Limitations: Exception handling is not complete.
  11.  
  12. ********************************************************************/
  13.  
  14. /************* import libraries ************************************/
  15. import java.text.NumberFormat;
  16. import java.util.Locale;
  17. import javax.swing.*;
  18. /*******************************************************************/
  19.  
  20. public class AmortizationTable
  21. {
  22. private static final int FLD_WIDTH = 11;
  23.  
  24. private AmoritizationData amoritizationTable[];
  25. private MortgageInformation mortgageInfo;
  26.  
  27. public AmortizationTable(double principal, double term, double apr)
  28. {
  29. mortgageInfo = new MortgageInformation(principal, term, apr);
  30. }
  31.  
  32. public AmortizationTable(MortgageInformation info)
  33. {
  34. this.mortgageInfo = info;
  35. }
  36.  
  37. public void DisplayAmortizationTable()
  38. {
  39. JTextArea tableArea = new JTextArea(30, 50);
  40. JScrollPane scrollpane;
  41. String output = new String();
  42.  
  43. CalculateAmortizationTable();
  44.  
  45. //include the loan information as the header
  46. output = mortgageInfo.HeaderString() + "\n\n";
  47.  
  48. //add the table
  49. output += getAmortizationTable();
  50.  
  51. tableArea.setText(output);
  52. scrollpane = new JScrollPane(tableArea,
  53. ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
  54. ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
  55.  
  56. JOptionPane.showMessageDialog(null,
  57. scrollpane,
  58. "Amortization Table",
  59. JOptionPane.INFORMATION_MESSAGE);
  60. }
  61.  
  62. private void CalculateAmortizationTable()
  63. {
  64. int numPayments = mortgageInfo.NumberPayments();
  65. double intRate = mortgageInfo.MonthlyRate();
  66. double principal = mortgageInfo.getPrincipal();
  67. double payment = mortgageInfo.Payment();
  68.  
  69. double loanBalance;
  70. double interestPaid;
  71. double principalBalance;
  72. double interestBalance;
  73. double principalPaid;
  74. double totalPaid;
  75. double totalInterestPaid;
  76.  
  77. //calculate total paid on the loan over the entire term of the loan
  78. totalPaid = numPayments * payment;
  79.  
  80. //calculate total interest paid over the entire term of the loan
  81. totalInterestPaid = totalPaid - principal;
  82.  
  83. //make room for the initial entries
  84. amoritizationTable = new AmoritizationData[numPayments + 1];
  85. //order of arguments in constructor are:
  86. //period, loanBalance, principalBalance, interestBalance, principal paid, interestPaid
  87. amoritizationTable[0] = new AmoritizationData(0, totalPaid, principal, totalInterestPaid, 0, 0);
  88.  
  89. //intialized the Amortization Table to the initial loan values, so start counting at 1
  90. for(int count = 1; count < amoritizationTable.length; count++)
  91. {
  92. //calculate loan balance from previous loan balance and mortgage payment
  93. loanBalance = amoritizationTable[count-1].loanBalance - payment;
  94.  
  95. //interest payment is the product of the interest rate per period and the remaining balance
  96. //remaining balance is the previous periods Principal Balance
  97. interestPaid = intRate * amoritizationTable[count-1].principalBalance;
  98.  
  99. //calculate new principal balance from previous principle balance, payment, and interest paid
  100. principalBalance = amoritizationTable[count-1].principalBalance - (payment - interestPaid);
  101.  
  102. //calculate interest balance using previous interest balance and new interest payment
  103. interestBalance = amoritizationTable[count-1].interestBalance - interestPaid;
  104.  
  105. //Calculate principal paid using previous principle paid, payment, and interest paid
  106. principalPaid = amoritizationTable[count-1].principalPaid + (payment - interestPaid);
  107.  
  108. //Calculate total interest paid, using the previous total interest paid and current interest paid
  109. totalInterestPaid = amoritizationTable[count-1].interestPaid + interestPaid;
  110.  
  111. //generate new data entry in the amortization table
  112. //period, loanBalance, principleBalance, interestBalance, principalPaid, interestPaid
  113. amoritizationTable[count] = new AmoritizationData(count,
  114. loanBalance,
  115. principalBalance,
  116. interestBalance,
  117. principalPaid,
  118. totalInterestPaid);
  119. }
  120. }
  121.  
  122. private String getAmortizationTable()
  123. {
  124. String output = new String();
  125. NumberFormat mf = NumberFormat.getCurrencyInstance( Locale.US);
  126. NumberFormat nf = NumberFormat.getNumberInstance();
  127. nf.setMaximumFractionDigits(2);
  128.  
  129. output = "# \tLoan Balance\tPrin Balance\tInt Balance\tPrin Paid\tInt Paid\n" +
  130. "---\t------------\t------------\t-----------\t-----------\t-----------\n";
  131.  
  132. for (int i = 0; i < amoritizationTable.length; i++)
  133. {
  134. output = output + amoritizationTable[i].period + "\t" +
  135. Justify.right(mf.format(amoritizationTable[i].loanBalance), FLD_WIDTH) + "\t" +
  136. Justify.right(mf.format(amoritizationTable[i].principalBalance), FLD_WIDTH) + "\t" +
  137. Justify.right(mf.format(amoritizationTable[i].interestBalance), FLD_WIDTH) + "\t" +
  138. Justify.right(mf.format(amoritizationTable[i].principalPaid), FLD_WIDTH) + "\t" +
  139. Justify.right(mf.format(amoritizationTable[i].interestPaid), FLD_WIDTH) + "\n";
  140. }
  141. return output;
  142. }
  143. }
Last edited by adatapost; Feb 8th, 2010 at 6:10 am. Reason: Added [code] tags. Encase your code in: [code] and [/code] tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bardcode1 is offline Offline
2 posts
since Feb 2010
Feb 8th, 2010
0
Re: mortgage calculator help
Please use code tags and try to point us to the part of the code you are having problems with
Sponsor
Featured Poster
Reputation Points: 1005
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,256 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Palindromes strings
Next Thread in Java Forum Timeline: connectToActiveInstance of Internet Explore





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC