Help with Mortgage calculator program

harryt123's Avatar, Join Date: Jun 2006
Newbie 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.

Code:
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. 
      
    }
}
0
rheamae05's Avatar, Join Date: Jul 2008
Newbie Member
The code script is good! What site are you working with?
0
Mviner's Avatar, Join Date: Jul 2008
Newbie Member
Do you have any website where you uploaded this to see how it works ?