我需要幫助來迭代循環中的月份計算和列表。需要幫助Java攤銷表
我不知道如何使用更新信息列出貸款餘額。此代碼在每個地方列出項目,但每個編號與最後一個編號相同。第一個月的計算顯示整個360個月。
用Java編寫程序(無圖形用戶界面) 使用貸款金額200,000美元,利率爲5.75% 和30年期限。顯示抵押付款金額,然後 列出貸款餘額和每筆付款的利息支付期限爲 。如果列表滾動出屏幕, 使用循環顯示部分列表,猶豫, ,然後顯示更多的列表。提前
/聲明所有變量3周/
double anualInterest = .0575;
double interestCompoundedMonthly = 0;
double interestForPeriod = 0;
double principalAtEndOfPeriod = 200000.00;
double portionToPrincipal = 0;
double amountOfPaymentMonthly = 1167.15;
double newPrincipalAtEndOfPeriod = 0;
/計算支付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
}
}
}
}
}