void setup() {
size(500, 600);
background(126, 36, 12);
textAlign(LEFT);
textSize(20);
fill(0, 255, 0);
text("Monthly Loan Payment", 170, 30);
textSize(13);
fill(0, 0, 255);
float loanAmount = 5000;
float loanTerm = 1;
float interestRate = 12;
loanPayment(loanAmount, loanTerm, interestRate);
}
void loanPayment(float loanAmount, float loanTerm, float rate) {
loanTerm = loanTerm*12;
float percen = ((rate/100)/loanTerm);
float B = percen/(1-(pow(1+percen, -loanTerm)));
float paymentAmount = loanAmount*B;
float payment12month = paymentAmount*loanTerm;
text("Loan Amount : $"+loanAmount, 10, 65);
text("Loan Term : "+(int)(loanTerm)+" months", 10, 90);
text("Interset Rate : "+nf(rate, 0, 2)+" %", 10, 115);
text("Payment Every Month : $"+nf(paymentAmount, 0, 2), 275, 65);
text("Total of 12 Payments : $"+nf(payment12month, 0, 2), 275, 90);
text("Total Interset : $"+nf((payment12month-loanAmount), 0, 2), 275, 115);
int count = 1;
float interest = loanAmount*((rate/100)/loanTerm);
float principal = paymentAmount - interest;
float endBal = loanAmount - principal;
float totalInterest = interest;
float begin;
int y = 25;
text("Payment No.", 20, 155);
text("Interest", 120, 155);
text("Princical", 200, 155);
text("Unpaid Balance", 280, 155);
text("Total interest", 400, 155);
while (count <= loanTerm) {
text(nf(count, 2), 50, 155+y);
text("$"+nf(interest, 0, 2), 120, 155+y);
text("$"+nf(principal, 0, 2), 200, 155+y);
text("$"+nf(endBal, 0, 2), 300, 155+y);
text("$"+nf(totalInterest, 0, 2), 420, 155+y);
begin = endBal;
interest = begin*((rate/100)/loanTerm);
principal = paymentAmount - interest;
endBal = abs(begin - principal);
totalInterest = totalInterest + interest;
count = count +1;
y = y + 30;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น