Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,400 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,587 people online right now. Registration is fast and FREE... Join Now!




Mortgage Calculator

 

Mortgage Calculator

gday21

3 Jul, 2009 - 09:29 AM
Post #1

New D.I.C Head
*

Joined: 26 Apr, 2009
Posts: 29

I need to use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen. I have the mortgage payment amount for each loan. I NEED help with listing the loan balance and interest paid for each payment over the term of the loan.
CODE

public class MortgageCalculator4 {
  
   /*
    * - The main method.
    */
       public static void main(String args[]) {
      
      /*
       * Sets the amount of the mortgage for the calculation of the
       * loan.
       */
         double amount = 200000;
      
      /*
       * Define the matrices to store information of the loans. They
       * store the term (in years) and the interest rate of each loan.
       */
         int term[] = { 7, 15, 30 };
         double interestRate[] = { 5.35, 5.5, 5.75 };
      
      /*
       *  Print the amount of the Mortgage.
       */
         System.out.println(String
            .format("Amount of the Mortgage: %.2f", amount));
      
      /*
       * Defines a format string to print information about each
       * loan. Here we declare a variable to store the calculated monthly
       * payment. This two variables, "fmt" and "monthlyPayment" are used
       * inside the for loop.
       */
         String fmt = "\t[Loan %d] Term: %2d year(s)  Interest Rate: %6.2f%%  Monthly Payment: $%6.2f";
         double monthlyPayment;
      
      
      /*
       * The "for loop" to process the arrays.
       */
      
         for (int i = 0; i < term.length; i++) {
        
         /*
          * - Calculates the monthly payment of the loan
          */
            monthlyPayment = calculateMonthlyPayment(amount, interestRate[i],
               term[i]);
        
         /*
          * Prints the informations gathered, using the format
          * string "fmt".
          */
            System.out.println(String.format(fmt, i + 1, term[i],
               interestRate[i], monthlyPayment));
         }
      
      }
  
   /*
    *  The calculateMonthlyPayment method.
    *
    */
       public static double calculateMonthlyPayment(double amount,
           double interestRate, int term) {
          
      //
      // The formula has a principal, P, interest rate, r,
      // and number of monthly payments, m.
      //
      // The down payment is included in P.
      //
      // P ( r / 12 )
      // -------------------------
      // (1 - pow( 1 + r / 12, -m ) )
      //
      
         double p = amount;
         double r = interestRate / 100.00 / 12.00;
         int n = (term * 12);
      
         double num = p * r;
         double den = (1 - Math.pow(1 + r, -n));
      
         return den != 0 ? num / den : 0;
      
      }
   }
Can anyone help me??

User is offlineProfile CardPM
+Quote Post


pbl

RE: Mortgage Calculator

3 Jul, 2009 - 01:20 PM
Post #2

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,537



Thanked: 1126 times
Dream Kudos: 450
My Contributions
There are at least 500 Mortgage Calculator program examples in this forum
It seems to be one of the favourite teachers' assigment
just search the forum for Mortgage
you'll find console mode ones that are later translated into GUI ones
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:17PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month