Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4623076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:56:04+00:00 2026-05-22T02:56:04+00:00

This is my homework it is due Monday the 16th. I finally got the

  • 0

This is my homework it is due Monday the 16th.
I finally got the months to display right but the amounts are wrong.
Also, not necessary but it would be nice to stop and Print something between each loan.
Like loan 1, loan 2, loan 3…

Any help will be appreciated

/*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%

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.*/

I have the months correct but the loan amounts are wrong.

    import java.io.IOException;      //Code that delays ending the program


   class MonthlyRhondav4
    {      

  public static void main ( String[] args) throws IOException{

     double loanAmount = 200000.00;   // $ amount borrowed
     double monthlyPayment = 0;   // monthly payment for calculating
     double loanBalance;
     double interestPaid;
     double principalPaid;
     int paymentCounter;
     int lineCounter = 0;



     java.text.DecimalFormat dcm = new java.text.DecimalFormat("$,###.00");                                      


     int termArray[] = {84, 180, 360};      // Different loan terms in months 
     double interestArray[] = {0.0535, 0.055, 0.0575};// Different interest rates for the loan
     int k =0;// gonna be paymentIndex

  /*Code to start the payment list*/   

     System.out.print("\n\nPlease Press Enter to Continue to the 3 Different    Amortization Lists");
     System.out.println ();
     System.out.println ();

     System.in.read();
     System.in.read();  

  /*Display columns*/    

     System.out.println("Month \t Loan Amount Left\tInterest\t\tPrincipal \n"); //Prints headers for columns
     System.out.println ();


  /*Loop to calculate and print monthly payments*/

     //for(k=0; k<3; k++){// k is going to be paymentIndex to loop through index

     for (k = 0; k < interestArray.length; k++) {

        for(paymentCounter =1; paymentCounter <= termArray[k]; paymentCounter++)  // months through array
        { 

        /********TROUBLE HERE***************************************************************************************/

           monthlyPayment = ((loanAmount * (interestArray[k]) * termArray[k]) + loanAmount) / (termArray[k] * 12);

           interestPaid = loanAmount*(interestArray[k]/12);            //interest paid through array

           principalPaid = monthlyPayment-loanAmount*(interestArray[k]/12);       //principal paid

      /*need to fig monthly payment+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/




           System.out.println(paymentCounter + "\t" + dcm.format(loanAmount) + "\t\t" + dcm.format(interestPaid) + "\t\t\t" + dcm.format(principalPaid));



           lineCounter++;                                //Increment the display counter
           if (lineCounter > 11 && paymentCounter < termArray[k]*12) //Check to see if 12             
           {

              System.out.println ("Please Press Enter to Continue the List" ); //Code to delay ending the program
              System.in.read();
              System.in.read();
              lineCounter = 0; 

           }

        }
        loanAmount = (loanAmount - (monthlyPayment-loanAmount*(interestArray[k]/12))); //Calculate new loan amount
     }


  }//ends public static void main 
     }//ends public class 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:56:04+00:00Added an answer on May 22, 2026 at 2:56 am

    One observation — you’re not doing anything with the loan balance. The reason why nothing is changing is that having computed the interest and principal amounts of a given payment, you’re not reducing the loan balance by the principal portion of the payment. You need to change your code to display the current loan balance and to compute the principal/interest split from the current loan balance and not the original loan amount.


    Edited

    Ok — I see you were trying to update the balance, but you have it outside the loop for the loan. That needs to be inside the loop so that it is updated for each payment. Also, you have things like loanAmount * (interestArray[k] / 12) over and over again. Consider using variables, such as

    double interestPaid = loanAmount * (interestArray[k] / 12)
    

    This will make your code easier to read and more maintainable since if you find a mistake in the calculation, you only have to fix the mistake in one place rather than having to fix it everywhere you had the calculation.

    I also don’t see where you’re calculating the monthly payment. That’s a function of the original loan amount, number of payments, and interest rate. Remember, the monthly payment is fixed and the interest/principal split of each payment will change as the loan is paid down. You might find http://en.wikipedia.org/wiki/Mortgage_calculator useful to figure out the formula for the monthly payment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is for homework due yesterday but I do not want the answer just
well I'm doing this homework but I'm still not viewing the fault... When I
The answer to this sample homework problem is "1,000,000", but I do not understand
(Before anyone says anything Yes this was homework but i have already turned it
I have this homework that I gotta finish, but then something about it is
I am stumped on this homework problem. I think I have the right answer
Alright, i had this homework recently (don't worry, i've already done it, but in
This is homework, but I need a nudge. I can't find how to sort
hi everyone I'm here again, this week I got this Homework: I should find
I have an emergency here. This homework is due tomorrow for my CP 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.