Trouble getting code to display in columns

Posted on 2009-12-20
Last Modified: 2013-11-23
Can anyone help me? I have created a code but it does not display the numbers in 7 columns.

Here is my assignment requirements and I will attach my code as well. I do not have much time before submitting. Thanks.

Here is my assignment.

Java mortgage calculator
Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans.
7 years at 5.35%
15 years at 5.5%
30 years 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.

Name your program file, XXX is your last name. It is important to use your last name so that each students program file is unique. When your team evaluates the members program, the team will know whom the program belong to. Not naming the file will cause point deduction. Submit your .java file into your individual forum under the ASSIGNMENT THREAD.

1.      The program should require two user input values.
2.      The first input value is the loan amount.
3.      The second input value is an indicator for displaying the balance and interest paid list.
4.      Error checking should be done on the input loan amount to make sure that it is a positive number and is not zero.
5.      If the input loan amount is wrong, show an error message and exit the program.
6.      If the input loan amount is correct, proceed to compute.
7.      If the indicator is not to show the list, then only show the mortgage payments. Below is an example:
Loan amount $200000
Loan Term      Interest Rate      Mortgage Payment
7 years      5.35%      $2859.79
15 years      5.5%      $1634.17
30 years      5.75%      $1167.15

8.      If the indicator is to show the list, the program should show the mortgage payments first as in step 7. Following the mortgage payments, the list should be shown in 7 columns. The column are:
Column 1 - payment number
Column 2  the first loan balance
Column 3  the first loan interest paid
Column 4  the second loan balance
Column 5  the second loan interest paid
Column 6  the third loan balance
Column 7  the third loan interest paid
See example below on a $200000 loan:
1      198031.88      891.67      199282.50      916.67      199791.19      958.33
2      196054.98      882.89      198561.71      913.38      199581.38      957.33
3      194069.27      874.08      197837.62      910.07      199370.56      956.33
Question by:coldjava
    LVL 5

    Expert Comment

    First, your program has to accept the loan amount.  For that, check here:

    I attach a changed class that shows how to display data in columns.


    Author Comment

    BlackFrancis75 --

    I have tried to add information so it will display in columns according to the assignment instructions. My Command Prompt is weird. It will allow me to execute Week4 but since then I have tried to execute Week 5 or Week 6 and it cannot find the path.

    Anyway can you check my code again and tell me if I am doing this correctly?

    There are supposed to be 7 columns:

    Column 1 -payment number
    Column 2 - the first loan balance
    Column 3 - the first loan interest paid
    Column 4 - the second loan balance
    Column 5 - the second load interest paid
    Column 6 - the third loan balance
    Column 7 - the third loan interest paid.
    LVL 11

    Expert Comment


    I have made changes to display the data in the given format. However, there are still multiple things that needs to be changed that I leave for you to continue. Let me know if you still need help and I can make changed to the program accordingly.

    1. Need to accept in put for amount and list indicator. Set the class level values and show list accordingly
    2. The mortgage formula seems to be wrong. Check it and make changes accordingly.
    3. Change the class to make the methods belong to class. In main() create an instance of class and use it to call methods.

    Author Comment

    Anilallewar --

    Thanks for the help. I will work on your suggestions today.  

    Author Comment

    Anilallewar --

    My instructor provided a more detailed assignment for what I am working on.
    Is it difficult create a no or yes option in code? I have some code I worked on concerning display and a user option but I am not sure it is correct. I am attaching the code for this that I have worked on. Thanks.

    Here is what he gave me:
    About the 7 columns, here is how the program should run.
    1. When the program runs, it asks the user to enter a loan amount, such as $200000
    2. Then it asks the user to enter an indicator to see if the user wants to view the amortization 7 column table or not.
    3. If the user input an indicator that is No, then the program displays:

    Loan amount $200000

    Loan Term

    Interest Rate

    Mortgage Payment

    7 years



    15 years



    30 years



    4. If the user input Yes to see the amortization schedule, the program should display the values in step 3 and the 7 column table.

    When I test the program, I will run the program with a No answer. Then I will run the program with a Yes answer. Your screen shot output is should be the same as step 3 above if you use a $200000 loan amount.

    LVL 11

    Accepted Solution


    Attached is the running program. Since I had some extra time today, I also modularized the code in line with OO principles. Please add necessary formatting and check the formulas before submission. Best of Luck!!

    Author Comment


    Thanks so much for the help on this project.

    I will work on this today.


    Author Comment

    Anilallewar --

    I have encountered two problems.
     When I get to the portion where the user enters the 200000 amount and then the "yes" option, instead of 7 columns displaying and stopping -- it just keeps going endlessly.

    The second problem is that when these multiple columns display it is all zeros. I have worked on a code for displaying the 7 columns. Does this look accurate? Thanks.  

      DecimalFormat decimalPlace=new DecimalFormat("$000,000.00");

            //Declares and builds the variables
            double[] loanTerm= new double[3];

                //Displays the mortgage calculator
                System.out.println("payment number");
                System.out.println("the first loan balance");
                System.out.println(the first loan interest paid);
                System.out.println(the second loan balance);
                System.out.println(the second loan interest paid);
                System.out.println("the third loan balance");
                System.out.println(the third loan interest paid);

                    //Declares and builds three new variables
                    double loanBalance = 0;
                    double interestPaid = 0;
                    int lineCount = 20;
                    loanBalance = loanAmount - monthlyPayment;

                    //Starts loop statement,and declares formula for loan balance and interest paid
                    while (loanBalance > 0) {

                    //Declares formula
                    double Payment1= Math.round(loanAmount*(interestMonthly[1]/(1-Math.pow((1 + interestMonthly[1])-loanTerm[1])))*100);
                    double Payment2= Math.round(loanAmount*(interestMonthly[2]/(1-Math.pow((1 + interestMonthly[2])-loanTerm[2])))*100);
                    double Payment3= Math.round(loanAmount*(interestMonthly[3]/(1-Math.pow((1 + interestMonthly[3])-loanTerm[3])))*100);

                    //Displays the monthly payment for each option.
                    System.out.println("Mortgage payment for 7 years is " + decimalPlace.format(Payment1));
                            System.out.println("Mortgage payment for 15 years is " + decimalPlace.format(Payment2));
                            System.out.println("Mortgage payment for 30 years is " + decimalPlace.format(Payment3));

                    loanBalance = loanBalance - monthlyPayment;
                    interestPaid = (monthlyPayment * interestMonthly);


    Author Closing Comment

    Volunteer did a good job on helping me.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One Java Help from Top Experts

    Solve your toughest problems, fast.
    Java experts are online now and ready to help you.

    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now