[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Problem with my for loop

Asked by Bulldozer in Programming Languages, Java Programming Language, New to Java Programming

Tags: How do I get 12 payments at a time to show up

for (i=0;i<terms.length;i++) {        //Problem getting 12 payments to display

Comman Prompt results
 Monthly Payment:$ 2897.80

 **********************************************************
No.     Interest Paid    Principal Paid    Loan Balance

Press Enter to View next 12 Months
// payments are missing
Press Enter to View next 12 Months
//payments are missing
85          958.33         1939.47        198060.53

Please help explain what I am doing wrong so I can fix my loop to work properly
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
import java.io.*;
import java.util.Formatter;
import java.text.*;
import java.util.Arrays;
import java.io.IOException;
 
public class LoanArray // name the class file
{
public static void main(String[] args)throws IOException // Method Main runs program with exceptions
	{
    double[] totalYears = {7,15,30}; // set array for number of years for term of loan
	Formatter fmt = new Formatter(); //interpreter for printf-style strings
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader bfr = new BufferedReader(isr);
 
	for (int i=0;i<totalYears.length;i++){
		int[] termMonths = {(7*12), (15*12), (30*12)}; // set array for number of months for term of loan
		double []terms = {84,180,360};
		double[] interestPaid = {(5.75/1200), (5.5/1200), (5.35/1200)}; //set array for interest paid
		double[] interestPaidRate = {5.75, 5.5, 5.35}; // set array for annual interest paid rate
		double totalPrincipal = 200000; // set total principal
		double moPayment = 0; // set all fields to zero
		double newBal = totalPrincipal; // balance after each moPayment
		double newPrinc;// Amount paid on principal
		double newinterestPaid; //Amount paid on interestPaid
		String ssetprinc = "200,000";
 
			//Calculate Monthly Loan moPayment
		moPayment = (totalPrincipal * interestPaid[i]) / (1.0 - (Math.pow((1.0 + interestPaid[i]), - termMonths[i])));// increases the amount based on number on months
			//Screen Output Summary Displays to Dos command window
		System.out.printf("\nMortgage Payment Calculator\t version: 1.3\n\n"); //Program title and version
		
		System.out.printf(" Total Loan Amount:$ %s\n\n",ssetprinc);
		System.out.printf(" Interest Rate: %.2f\n\n",interestPaidRate[i]);
		System.out.printf(" Total Years of Loan: %4.0f\n\n",totalYears[i]);
		System.out.printf(" Monthly Payment:$ %.2f \n\n",moPayment);
		System.out.printf(" **********************************************************\n");
 
		//Screen Output Header for Amortization
		System.out.printf("No.\t"); // Shows what moPayment number it is
		System.out.printf("Interest Paid\t ");//Shows how much was applied to interestPaid
		System.out.printf("Principal Paid\t");//Shows how much was applied to principal
		System.out.printf("   Loan Balance    \n\n");
		System.out.println("Press Enter to View next 12 Months");
        bfr.readLine();
 
			//Display Amortization Schedule by month times number of years
 
	 for (i=0;i<terms.length;i++) {   //Problem getting 12 payments to display 
 
 
         {
				newinterestPaid = (newBal * interestPaid[i]);
				newPrinc = (moPayment - newinterestPaid);// Amount paid on principal
				newBal = (newBal - newPrinc); //Revise incremental balance on interestPaid
 
				if (termMonths[i] == totalYears.length * 12 - 1) { 		// prevent negative values
					moPayment = 0;
				}
				if (termMonths[i] % 12 == 0 && termMonths[i] != 0) {  //Waits for keypress to show next 12 months
					System.out.println("Press Enter to View next 12 Months");
					bfr.readLine();
 
				}
            System.out.printf("%s\t",termMonths[i] + 1); // Display the Payment Number
			//System.out.println((termMonths[i] + 1) + "   \t"); // Displays the Payment number
            System.out.printf("%10.2f\t",newinterestPaid);//Shows the interestPaid amount
            System.out.printf("%10.2f\t",newPrinc);//Shows the amount used to pay down debt
            System.out.printf(" %10.2f\n\n",newBal);//Displays the Amount Left to pay
			}
		}
	}
}
}
[+][-]10/28/09 07:48 AM, ID: 25683841Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Programming Languages, Java Programming Language, New to Java Programming
Tags: How do I get 12 payments at a time to show up
Sign Up Now!
Solution Provided By: amitkathpal123
Participating Experts: 2
Solution Grade: A
 
[+][-]10/28/09 07:23 AM, ID: 25683523Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/28/09 07:24 AM, ID: 25683530Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/28/09 07:29 AM, ID: 25683583Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625