2011-05-03 2 views
-1

계산을 반복하고 개월 동안 반복 목록에 도움이 필요합니다.도움이 필요 자바 상환 표

업데이트 된 정보로 대출 잔액을 표시하는 방법을 모르겠습니다. 이 코드는 각 장소의 항목을 나열하지만 각 숫자는 마지막 것과 같습니다. 첫 달 계산은 전체 360 개월 동안 표시됩니다.

금리가 5.75 % 이며 대출 기간이 $ 200,000이고 30 년 기간 인 Java (그래픽 사용자 인터페이스 제외) 으로 프로그램을 작성하십시오. 모기지 지불 금액을 표시 한 다음 은 대출 기간과 각 지불에 대해 지불 한 대출 잔액 및이자를 에 나열합니다. 목록이 화면에서 스크롤되면 루프를 사용하여 부분 목록을 표시하고, 을 주저하고 목록을 더 표시합니다. 어떤 조언에 미리

 double anualInterest = .0575; 
    double interestCompoundedMonthly = 0; 
    double interestForPeriod = 0; 
    double principalAtEndOfPeriod = 200000.00; 
    double portionToPrincipal = 0; 
    double amountOfPaymentMonthly = 1167.15; 
    double newPrincipalAtEndOfPeriod = 0; 

//

주 3

/선언 모든 변수를 계산 지불 주 3/

 interestCompoundedMonthly = (anualInterest/12); //.0575/12=.0047916 

     interestForPeriod = interestCompoundedMonthly * principalAtEndOfPeriod; // 958.32 =.0049916*200,000 

     portionToPrincipal = amountOfPaymentMonthly - interestForPeriod; // 208.83 = 1167.15-958.32 

     newPrincipalAtEndOfPeriod = principalAtEndOfPeriod - portionToPrincipal; //199791.18 = 200000-208.83 

     System.out.println (i+ "\t\t" + dcm.format(monthlyPayment)+"\t\t" +dcm.format(interestForPeriod)+"\t\t\t"+dcm.format(portionToPrincipal)+ "\t\t\t" +dcm.format(newPrincipalAtEndOfPeriod)); 

감사합니다.

/**************** 
* Week 2  * 
****************/ 
    /*Monthly Payment Program 
    A program written in Java (without a graphical user interface) 
    that will calculate and display the monthly payment amount 
    to fully amortize a $200,000.00 loan 
    over a 30 year term at 5.75‰ interest.*/ 

/**************** 
* Week 3  * 
****************/ 

    /* Write the program in Java (without a graphical user interface) 
    using a loan amount of $200,000 with an interest rate of 5.75% 
    and a 30 year term. Display the mortgage payment amount and then 
    list the loan balance and interest paid for each payment over 
    the term of the loan. If the list would scroll off the screen, 
    use loops to display a partial list, hesitate, 
    and then display more of the list.*/ 

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


    public class Monthly_Payment_Calculator { 
    public static void main (String [] args) { 



    /*Declare all Variables Week 2*/ 

    /*Variables provided by customer*/ 

    double loanAmount = 200000.00; // $ amount borrowed 
    double interestRate = 5.75;  // interest rate 5.75% 
    int years = 30;    // years of loan 

    /*Variables needed for calculating*/ 

    int months = 0;   // months for calculating 
    double monthlyPayment = 0; // monthly payment for calculating 
    double interest = 0;  // interest rate for calculating 

    /*Declare all Variables for Week 3*/ 

    double anualInterest = .0575; 
    double interestCompoundedMonthly = 0; 
    double interestForPeriod = 0; 
    double principalAtEndOfPeriod = 200000.00; 
    double portionToPrincipal = 0; 
    double amountOfPaymentMonthly = 1167.15; 
    double newPrincipalAtEndOfPeriod = 0; 

    /*Variables for storing previous balances*/  




    java.text.DecimalFormat dcm = new java.text.DecimalFormat("$,###.00");  
           // format for currency 


    /*Calculate Payment Week 2*/ 

    interest = interestRate/100; 

    months = years * 12; 

    monthlyPayment = (loanAmount * (interest/12))/(1 - 1 /Math.pow((1 + interest/12), months));  


    /*Display the mortgage payment amount as per WK3 assignment*/ 

    System.out.println ("Total Monthly Payment is ");   
    System.out.println (dcm.format(monthlyPayment));   


    /*Display columns*/ 
    System.out.println("Month #\t Amount of Payment\tInterest for Period\tPortion to Principal\tPrincipal at End of Period\n"); 
    System.out.println("0\t\t\t0\t\t0\t\t\t0\t\t\t"+ dcm.format(principalAtEndOfPeriod)); 
    //Prints headers for columns 


    /*Loop to calculate and print monthly payments*/ 

    for(int i=1; i <= months; i++) // 360 months 
    { 

    /*Calculate Payments Week 3*/ 


     interestCompoundedMonthly = (anualInterest/12); //.0575/12=.0047916 

     interestForPeriod = interestCompoundedMonthly * principalAtEndOfPeriod; // 958.32 =.0049916*200,000 

     portionToPrincipal = amountOfPaymentMonthly - interestForPeriod; // 208.83 = 1167.15-958.32 

     newPrincipalAtEndOfPeriod = principalAtEndOfPeriod - portionToPrincipal; //199791.18 = 200000-208.83 

     System.out.println (i+ "\t\t" + dcm.format(monthlyPayment)+"\t\t" +dcm.format(interestForPeriod)+"\t\t\t"+dcm.format(portionToPrincipal)+ "\t\t\t" +dcm.format(newPrincipalAtEndOfPeriod)); 


    //recalculate interest for period 
    //recalculate the portion to principal 
    //recalculate principal at end of period 
    //set the remaining balance as the mortgage loan for the next repetition 



     if(i%12==0 && i<months){ 


      /*Code to delay ending the program*/ 

      System.out.println(); 
      System.out.println(); 
      System.out.println ("(Please Press Enter to Continue the List)"); 
      System.out.println(); 
      System.out.println(); 
      System.out.println("Month #\t Amount of Payment\tInterest for Period\tPortion to Principal\tPrincipal at End of Period\n"); 
      try { 
       System.in.read(); //Read input from the keyboard 

      } 
       catch (IOException e) { //Catch the input exception 
       return; //and just return 

       } 
     } 
    } 
    } 

}

답변

0

내가 관심을 작동하지만 난 당신이 합계를 계산하려고 같은데요 방법을 잘 모르겠어요. 아마도 당신은 당신의 'for'루프에서 다음을 시도 할 수 있습니다 :

// a is the cummulative sum 
// b is the monthly calculation 
a = a + b; 
1

당신은 지불 계산의 말에 교장의 균형을 다시 설정해야합니다. 다음을 추가해보십시오.

prindipalAtEndOfPeriod = newPrincipalAtEndOfPeriod; 

나는 잠시지만 누군가 다른 사람이 도움이 될 것이라고 알고 있습니다.