[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Java Mortgage Calculator

Asked by major75 in New to Java Programming

Tags: Jaa

I would like to add loops to the following code that I have written so that it will display all of the information down to the last month. Can you help?

import java.text.DecimalFormat; //Required for format output
public class MortgagePaymentCalculator
{
        //Hard code the amount=400,000, the term=30 years, and the interest rate=4.75%
        static double MortgageAmount = 400000;  
          //400,000 is the amount of the mortgage
        static int TermYears = 30;                      
          //30 is the length of time that the amount is to be payed back
        static double InterestRate = 4.75;                
          //4.75 is the percentage of interest to be paid monthly
        static double MonthlyPayment;  
          //Total monthly payment
        static double MonthlyInterest;
        static int Months;
        static double MonthlyInterestRate;
        static int Payment;
        static double Balance;
        static double MonthlyInterestPaid;
        static double Principle;
          static int PaymentNumber;
          static double LastPrinciple;
          static int Delay;
  //Main
 
    public static void main(String[] args)
      {
          DecimalFormat Money = new DecimalFormat("$0,000.00");
         
           //Monthly Payment Calculations
            Months = (TermYears * 12);
            //Calculates the total number of months to pay mortgage (360)
            MonthlyInterestRate = (InterestRate *.01);
            //Calculates the rate to a decimal format
            MonthlyInterest = (MonthlyInterestRate/12);
            //Calculates the amount of monthly interest
            Balance = (MortgageAmount-MonthlyPayment);
            Principle = (MonthlyPayment-MonthlyInterestPaid);
               
               
            //Calculates monthly payment
            MonthlyPayment = MortgageAmount*(MonthlyInterest*Math.pow(1+MonthlyInterest,Months))/(Math.pow(1+MonthlyInterest,Months) -1);            
                //Calculates the monthly payment
                MonthlyInterestPaid = MonthlyInterest*Balance;                     
              //Calculates the monthly interest paid
              Balance = MortgageAmount - MonthlyPayment;
              //Calculates the Balance
              Principle = MonthlyPayment - MonthlyInterestPaid;
           //Monthly Mortgage Payment Calculator Heading

                  System.out.println("///////////////////////////////////////////////////////////////////////////////");

                  System.out.println("                       Monthly Mortgage Payment Calculator");

                  System.out.println("///////////////////////////////////////////////////////////////////////////////");
                  System.out.println("-------------------------------------------------------------------------------");
                  System.out.println();
                  //data produced from calculations
                  System.out.println("Total Mortgage Financed: "+ Money.format(MortgageAmount));
                  System.out.println();
                  System.out.println("Total Mortgage Term: "+ TermYears);
                  System.out.println();
                  System.out.println("Interest Rate: "+ InterestRate + "%");
                  System.out.println();
                  System.out.println("Monthly Payment At Given Interest Rate: " + Money.format(MonthlyPayment));
                  System.out.println("-------------------------------------------------------------------------------");
                  System.out.println();
                  //requesting the payment amount to be calculated
                    System.out.println("Payment #1");
                    System.out.println();
                  System.out.println("Payment Amount: " + Money.format(MonthlyPayment));
                  System.out.println("Interest Paid: " + Money.format(MonthlyInterestPaid));
                  System.out.println("Principle: " + Money.format(Principle));
                  System.out.println("Loan Balance: " + Money.format(Balance));
                  System.out.println();
                  System.out.println("-------------------------------------------------------------------------------");
                  System.out.println();
            }
   //Amortization
     
        /*
        @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
             Method:          getAmortization
           Description:  This method is established to calculate the "interest paid for each
                         over the term of the loan".                   
           parameters:   double Principle, double MonthlyPayment, double Balance
           return:         void
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    
        */
       
         public static void Amortization (double Principle, double MonthlyPayment, double Balance)
              {        
                  DecimalFormat Money = new DecimalFormat("$0,000.00");
                     
                        PaymentNumber = 1;
                       //Monthly Payment Calculations
                  Months = (TermYears * 12);
                  //Calculates the total number of months to pay mortgage (360)
                  MonthlyInterestRate = (InterestRate *.01);
                  //Calculates the rate to a decimal format
                  MonthlyInterest = (MonthlyInterestRate/12);
                  //Calculates the amount of monthly interest
                  Balance = (MortgageAmount-MonthlyPayment);
                  //Calculates the remaining balance
                    Principle = (MonthlyPayment-MonthlyInterestPaid);
                    LastPrinciple = (Principle);
                        Delay = 5000;
                       
                        //Calculates monthly payment
                  MonthlyPayment = MortgageAmount*(MonthlyInterest*Math.pow(1+MonthlyInterest,Months))/(Math.pow(1+MonthlyInterest,Months) -1);            
                  //Calculates the monthly payment
                  MonthlyInterestPaid = MonthlyInterest*Balance;                     
                  //Calculates the monthly interest paid
                  Balance = MortgageAmount - MonthlyPayment;
                  //Calculates the Balance
                  Principle = MonthlyPayment - MonthlyInterestPaid;
          
                        System.out.println();
                        System.out.println("Payment Number: " + PaymentNumber);
                  System.out.println("Payment Amount: " + Money.format(MonthlyPayment));
                  System.out.println("Interest Paid: " + Money.format(MonthlyInterestPaid));
                  System.out.println("Principle: " + Money.format(LastPrinciple));
                  System.out.println("Loan Balance: " + Money.format(Balance));
                  System.out.println();
                  System.out.println("-------------------------------------------------------------------------------");
                  System.out.println();
                  
        }//End Payment Calculations
       
}//End MortgagePaymentCalulator    
[+][-]11/01/09 03:52 PM, ID: 25716256Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: New to Java Programming
Tags: Jaa
Sign Up Now!
Solution Provided By: mwvisa1
Participating Experts: 1
Solution Grade: A
 
[+][-]11/01/09 04:21 PM, ID: 25716329Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625