1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Help with Mortgage calculator program

Discussion in 'Java' started by harryt123, Jun 15, 2006.

  1. harryt123

    harryt123 New Member

    I designed a Java mortgage program and it is working fine but I need to add some more things to it. I want to make the program list the loan balance and the interest paid for each payment over the term of the 30 year loan.(I want it to list for every 1 yr and then every couple of years). I want this list to scroll off the screen or even do a loop to show the partial list, hesitate and then display more of the list. I want to do this program with no GUI(graphical user interface). I will post my program coding below and any help would be appreciated greatly.

    public class MortgageProgram {
        public static void main (String[] args){
            double payment, principal = 200000; //*Principle amount of loan is $200,000
            double annualInterest = 0.0575; //*Interest rate is currently 5.75%
            int years = 30; //*Term of the loan is 30 years
            if (args.length == 3) {
                  principal = Double.parseDouble(args[0]);
                  annualInterest = Double.parseDouble(args[1]);
                  years = Integer.parseInt(args[2]);
               print(principal, annualInterest, years);
                System.out.println("Usage: Calculate Mortgage Payment Amount ");
                System.out.println("\nFor example: $200,000 Mortgage loan amount, 5.75% interest for a 30 year term "); //*States that Loan Amount is $200,000, interest is 5.75% and it is 30 year term. 
                System.out.println("\nThe Following is your output based on the hardcoded amount: \n"); //*Will show output in the following format
    	    print(principal, annualInterest, years);
                System.exit(0); //*System exits nice and quietly
        public static double calculatePayment(double principal, double annRate, int years){
            double monthlyInt = annRate / 12;
            double monthlyPayment = (principal * monthlyInt)
                        / (1 - Math.pow(1/ (1 + monthlyInt), years * 12)); //*Shows 1 monthly payment multiplied by 12 to make one complete year. 
            return format(monthlyPayment, 2);
        public static double format(double amount, int mortgage) {
            double temp = amount; 
            temp = temp * Math.pow(10, mortgage);
            temp = Math.round(temp);
            temp = temp/Math.pow(10, mortgage);
            return temp;
        public static void print(double pr, double annRate, int years){
            double mpayment = calculatePayment(pr, annRate, years);
            System.out.println("The principal is $" + (int)pr); //*Shows the principle amount in $ value. 
            System.out.println("The annual interest rate is " + format(annRate * 100, 2) +"%");
            System.out.println("The term is " + years + " years"); //*Term is normally in years.
            System.out.println("Your monthly payment is $" + mpayment); //*Shows output of monthly payment. 
  2. rheamae05

    rheamae05 New Member

    The code script is good! What site are you working with?
  3. Mviner

    Mviner Banned

    Do you have any website where you uploaded this to see how it works ?

Share This Page