Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Trouble getting code to display in columns

Posted on 2009-12-20
Medium Priority
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 XXXWeek2.java, 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
  • 6
  • 2

Expert Comment

ID: 26093466
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

ID: 26093603
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

ID: 26094103

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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 26096257
Anilallewar --

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

Author Comment

ID: 26101773
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

anilallewar earned 1000 total points
ID: 26102420

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

ID: 26105424

Thanks so much for the help on this project.

I will work on this today.


Author Comment

ID: 26114711
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

ID: 31668385
Volunteer did a good job on helping me.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
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.
Suggested Courses

572 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