• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

how do i modify this program so that it only displays the mortgage, principle, term and interest rate

how do i modify this program so that it only displays the mortgage, principle, term and interest rate
//-----------------------------------------------------------------------
// Mortgage Rate Calculator
//
// Daniel Gallant
// Unversity of Phoenix - POS 406
// Dan McAllister
// Version 1.1.01 | 05/04/07 Due -> 05/13/05
//--------------------------------------------------------------------


//Version control sheet
//Version 1.1.1 find similar code and find erros in syntax
//Version 1.1.2 explain how code works
//Version 1.2.1 rename variables used in calculation
//Version 1.2.2 replace monthsMonthlyRate [1]and [0] with param[1]and [0] variable
//verison 1.2.3 replace again param with monthlyMonthlyRt
//Version 1.3.1 compile and enter extra notes


//program originally written by 'daily dream' an alias which can linked to http://www.experts-exchange.com/M_3463278.html
//program code retrieved on april 10th, 2005 at http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21197647.html
// final editing done with help of Jim Cakalic 4-11-05 at http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21384460.html
 

      //import the java classes
import java.text.NumberFormat;
import java.util.Locale;

public class MortgageMulti {
    //MortgageMulti is the existing function
    public static void main(String[] arguments) {

        //hard code the value of the mortgage
        double mortgage = 200000.00;
        //hard code in the yearly interst rate
        double[][] yearsYearlyRate = {
            { 7, 15, 30 },
            { 5.35, 5.5, 5.75 }
        };
        //then code in the value for the number of times a year mulitplied by
        // the amoutn paid each time
        double[][] monthsMonthlyRt = {
            { yearsYearlyRate[0][0] * 12, yearsYearlyRate[0][1] * 12,
              yearsYearlyRate[0][2] * 12
            },
            { yearsYearlyRate[1][0] / 1200, yearsYearlyRate[1][1] / 1200,
              yearsYearlyRate[1][2] / 1200
            }
        };

        for (int i = 0; i < 3; i++) {

            //Call the method
            double payment = calPayment(monthsMonthlyRt[1][i], monthsMonthlyRt[0][i], mortgage);

            // Display the monthly payment
            System.out.println("\nMortgage Amount \tTerm \t\tRate \t\tMonthly Payment");
            System.out.println("$200,000 \t\t" + yearsYearlyRate[0][i] + " years\t"
                    + yearsYearlyRate[1][i] + "%\t\t" + payment);

            System.out.println("\nMonth # \tInterest for the Month \t\tLoan Balance");

            // Call the method
            interestBalanceList(mortgage, monthsMonthlyRt[1][i], monthsMonthlyRt[0][i], payment);
        }
    }

    // Utility method to calculate the monthly mortgage payment
    // (1st error spotted)public static double calPayment(double param1, double
    // param2, double mortgage);
    public static double calPayment(double param1, double param2, double mortgage) {

        // Calculate the monthlyPayment of the mortgage
        double monthlyPayment = (param1 + param2 / (Math.pow((1 + param1), param2) - 1)) * mortgage;

        return monthlyPayment;
    }

    // Utility method to list the interest paid and loan balance
    public static void interestBalanceList(double mortgage, double param1, double param2,
            double payment) {

        // Use the for loop to display the list
        for (int i = 1; i < (param2 + 1); i++) {

            // Pause the list and go to the next month and next amount
            System.out.println("Hit the 'ENTER' key to exit.");
            try {
                System.in.read();
            } catch (Exception e) {
            }
            // Calculate the monthlyInterest
            double monthlyInterest = mortgage * param1;

            // Calculate the loanBlance
            double loanRemaining = mortgage - (payment - monthlyInterest);

            // Set the value of mortgageAmount to the value of loanRemaining
            mortgage = loanRemaining;

            // Formate the monthlyInterest into U.S. currency
            NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US);
            String str = n.format(monthlyInterest);

            // Formate the loanRemaining into U.S. currency
            NumberFormat num = NumberFormat.getCurrencyInstance(Locale.US);
            String string = num.format(loanRemaining);

            // Display the month #, interest paid and loan balance
            System.out.println("\n " + i + "\t\t " + str + "\t\t\t" + string);

        }
    }
}
0
akaryu98
Asked:
akaryu98
  • 3
  • 2
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
0
 
akaryu98Author Commented:
whatt does that mean by the link. i need it explained to me and show which prat of the code to remove to get the display. not just the link to another question!!!
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Why did you accept that comment? It was a link to your own question. I meant that you should get this question deleted and your points refunded, because this was a duplicate of that one. You should ask one question only once :)
0
 
akaryu98Author Commented:
i am in a hurrry. andi would seem like an indian giver. you're right actually. but do you have an alternativ for this. i need to modif y this to show a mortgage scheddule for 30 years with 260 payments
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Well, I don't have time to look into your code right. Since you've deleted the other question and accepted this one, you should request Community Support to re-open this question so that other experts can post on this.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now