Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Homework

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Homework

    Not sure why it isnt working or what else I need to do. so any help would be great thanks

    Extend your Java Project with the following items:
    o Write the program in Java (without a graphical user interface) and have it
    calculate the payment amount for 3 mortgage loans:
     7 year at 5.35%
     15 year at 5.5%
     30 year at 5.75%
    o 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.

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package MortagePaymentCalculator;

    /**
    * @Author: JDonaldson
    * Date Written: 2/26/2011
    * Program Description: Week 3 Assignment
    */

    import static java.lang.Math.*; //Import static class members
    import java.text.DecimalFormat; //Import for decimal points


    public class Test3

    {


    public static void main (String [] args)

    {

    int i = 0;
    double LoanAmount = 200000;
    double LoanBalance = 0;
    double InterestPaid = 0;
    int LoanTerm[] = {84, 180, 360};
    double Interest[] = {.0535, .0550, .0575};
    double MonthlyPayment = 0;



    DecimalFormat Currency = new DecimalFormat ("$###,###.##");
    DecimalFormat Format = new DecimalFormat("0.##");



    if (i == 0)

    {
    MonthlyPayment = LoanAmount * (((Interest[2]/12) * Math.pow((1 + (Interest[2]/12)), LoanTerm[0])) / (Math.pow((1 + (Interest[2]/12)), LoanTerm[2]) - 1));


    LoanBalance = LoanAmount - MonthlyPayment;
    InterestPaid = MonthlyPayment * Interest[0];

    //Displays calculations for first loan

    System.out.println("McBride Financial Services Mortgage Calculator");

    System.out.println("The loan amount is: $200,000");

    System.out.println("The term of the loan is:" + LoanTerm[0]);

    System.out.println("The monthly payment is: $" + Format.format(MonthlyPayment));

    System.out.println("The loan balance is: $" + Format.format(LoanBalance));

    System.out.println("The interest paid is: $" + Format.format(InterestPaid));

    System.out.println();

    }
    if (i == 1)

    {

    MonthlyPayment = LoanAmount * (((Interest[1]/12) * Math.pow((1 + (Interest[1]/12)), LoanTerm[1])) / (Math.pow((1 + (Interest[1]/12)), LoanTerm[1]) - 1));

    LoanBalance = LoanAmount - MonthlyPayment;

    InterestPaid = MonthlyPayment * Interest[1];





    //Displays mortgage calculator

    System.out.println("McBride Financial Services Mortgage Calculator");

    System.out.println("The loan amount is: $200,000");

    System.out.println("The term of the loan is:" + LoanTerm[1]);

    System.out.println("The monthly payment is: $" + Format.format(MonthlyPayment));

    System.out.println("The loan balance is: $" + Format.format(LoanBalance));

    System.out.println("The interest paid is: $" + Format.format(InterestPaid));

    System.out.println();

    }

    if (i == 2)

    {

    MonthlyPayment = LoanAmount * (((Interest[2]/12) * Math.pow((1 + (Interest[2]/12)), LoanTerm[2])) / (Math.pow((1 + (Interest[2]/12)), LoanTerm[2]) - 1));

    LoanBalance = LoanAmount - MonthlyPayment;

    InterestPaid = MonthlyPayment * Interest[2];





    //Displays mortgage calculator

    System.out.println("McBride Financial Services Mortgage Calculator");

    System.out.println("The loan amount is: $200,000");

    System.out.println("The term of the loan is:" + LoanTerm[2]);

    System.out.println("The monthly payment is: $" + Format.format(MonthlyPayment));

    System.out.println("The loan balance is: $" + Format.format(LoanBalance));

    System.out.println("The interest paid is: $" + Format.format(InterestPaid));

    System.out.println();

    }


    for (int a=1;a<361;a++) //begin loop to show 360 payments

    {

    InterestPaid = (LoanAmount * Interest[2]);



    double principalPaid = MonthlyPayment - InterestPaid;

    LoanAmount = LoanAmount - principalPaid;




    System.out.println("\nMonthly Payment " + a + " = " + Currency.format (MonthlyPayment));

    System.out.println("Loan Balance = " + Currency.format (LoanBalance));

    System.out.println("Interest Paid = " + Currency.format(InterestPaid));





    if (a%6 == 0) // pause display between screens

    {

    try

    {

    Thread.sleep(1500);

    }

    catch(InterruptedException ie) {}


    }

    }

    }

    }


  2. #2
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default Re: Homework

    I haven't read the calculations for correctness, but the flow of your program seems to rely on the value of i which never changes, I'm guessing by design... and I see LoanBalance is never changed in the for loop.

    From what I see, this forum doesn't like when you post the complete code and just ask for help(especially if it's Homework). They/we expect you to try and figure out a general idea of the error, and show us what steps you've tried to resolve the error. Basically show us that you've put some effort into trying to resolve the issue. When you say it's not working, elaborate a little, show a sample of the current output, and tell us the desired output.

Similar Threads

  1. [SOLVED] Need statistics Homework help?
    By keith thomas in forum Java Theory & Questions
    Replies: 1
    Last Post: January 7th, 2011, 02:20 AM
  2. Homework help
    By cd247 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 11th, 2009, 05:56 PM
  3. need help with homework!
    By programmer12345 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 27th, 2009, 05:34 AM
  4. [SOLVED] What is cast operator and how to use it?
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 27th, 2009, 06:11 AM
  5. [SOLVED] Java program to prompt and display the user input number as odd or even
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 22nd, 2009, 01:19 AM