void setup() {
size(685, 500);
background(0);
fill(255);
monthly_loan_payment(5000, 12, 1);
}
void monthly_loan_payment(float loan_amount, float interest_rate, int loan_term) {
float ratepermonth = (interest_rate/100)/12;
float paypermonth = loan_amount*(ratepermonth/(1-pow(1+ratepermonth, -(loan_term*12))));//M=P*(J/(1-(1+J)^-n))
float unpaid = loan_amount;
float total_interest = 0;
int month = 1;
textSize(25);
text("Monthly Loan Payment", 205, 30);
textSize(17);
text("Payment No. Interest Principal Unpaid Balance Total Interest", 20, 70);
int Y =110;
while (month <= (loan_term*12)) {
float interest = ratepermonth*unpaid;
total_interest+=interest;
float principal = paypermonth-interest;
unpaid = abs(unpaid-principal);
text(nf(month, 2), 60, Y);
text("$"+nf(interest, 1, 2), 168, Y);
text("$"+nf(principal, 1, 2), 272, Y);
text("$"+nf(unpaid, 1, 2), 408, Y);
text("$"+nf(total_interest, 3, 2), 576, Y);
Y+=30;
month++;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น