//LOAN PAYMENT//
void setup() {
size(550, 525);
background(0);
textSize(20);
fill(255);
/////////////TITLE//////////////
text("Monthly Loan Payment", 140, 30);
textSize(13);
fill(255);
////////////FLOAT&FUNTION(LOANPAYMENT)//////////
float loan_Amount = 5000; // loan amount
float loan_Term = 1; // loan term
float interest_Rate = 12; // interest rate
loanPymt(loan_Amount, loan_Term, interest_Rate);
}
////////// Function:Loanpayment/////////////////////////
void loanPymt(float loanAnt, float loanTm, float rate) {
loanTm = loanTm*12;//year
///Calculation///
float j = ((rate/100)/loanTm);
float paymentAnt = loanAnt*(j/(1-(pow(1+j, -loanTm))));
float payment12mths = paymentAnt*loanTm;
textSize(10);
text("Loan Amount : "+loanAnt, 60, 65);
text("Loan Term : "+(int)(loanTm)+" months", 60, 90);
text("Interest Rate : "+nf(rate, 0, 2)+" %", 60, 115);
text("Payment Every Month : "+nf(paymentAnt, 0, 2), 240, 65);
text("Total of 12 Payments : "+nf(payment12mths, 0, 2), 240, 90);
text("Total Interest : "+nf((payment12mths-loanAnt), 0, 2), 240, 115);
/////////////////////// LOOP (WHILE)////////////////
int count = 1;
float unpaid = loanAnt;
float totalInterest = 0;
int posy = 25;
////////Title////////////////
textSize(15);
text("Payment No.", 10, 155);
text("Interest", 110, 155);
text("Principal", 190, 155);
text("Unpaid Balance", 270, 155);
text("Total interest to Date", 390, 155);
while (count <= loanTm) {
float interest = unpaid*j;
totalInterest = totalInterest+interest;
float principal = paymentAnt - interest;
unpaid = abs(unpaid - principal);
/////////////result////////////
//nf(value, "dot total")
text(count, 40, 155+posy);
text(nf(interest, 0, 2), 110, 155+posy);
text(nf(principal, 0, 2), 190, 155+posy);
text(nf(unpaid, 0, 2), 290, 155+posy);
text(nf(totalInterest, 0, 2), 430, 155+posy);
count++;///////UPDATE//////////
posy=posy+30;////////POSITION Y//////////
}
}
size(550, 525);
background(0);
textSize(20);
fill(255);
/////////////TITLE//////////////
text("Monthly Loan Payment", 140, 30);
textSize(13);
fill(255);
////////////FLOAT&FUNTION(LOANPAYMENT)//////////
float loan_Amount = 5000; // loan amount
float loan_Term = 1; // loan term
float interest_Rate = 12; // interest rate
loanPymt(loan_Amount, loan_Term, interest_Rate);
}
////////// Function:Loanpayment/////////////////////////
void loanPymt(float loanAnt, float loanTm, float rate) {
loanTm = loanTm*12;//year
///Calculation///
float j = ((rate/100)/loanTm);
float paymentAnt = loanAnt*(j/(1-(pow(1+j, -loanTm))));
float payment12mths = paymentAnt*loanTm;
textSize(10);
text("Loan Amount : "+loanAnt, 60, 65);
text("Loan Term : "+(int)(loanTm)+" months", 60, 90);
text("Interest Rate : "+nf(rate, 0, 2)+" %", 60, 115);
text("Payment Every Month : "+nf(paymentAnt, 0, 2), 240, 65);
text("Total of 12 Payments : "+nf(payment12mths, 0, 2), 240, 90);
text("Total Interest : "+nf((payment12mths-loanAnt), 0, 2), 240, 115);
/////////////////////// LOOP (WHILE)////////////////
int count = 1;
float unpaid = loanAnt;
float totalInterest = 0;
int posy = 25;
////////Title////////////////
textSize(15);
text("Payment No.", 10, 155);
text("Interest", 110, 155);
text("Principal", 190, 155);
text("Unpaid Balance", 270, 155);
text("Total interest to Date", 390, 155);
while (count <= loanTm) {
float interest = unpaid*j;
totalInterest = totalInterest+interest;
float principal = paymentAnt - interest;
unpaid = abs(unpaid - principal);
/////////////result////////////
//nf(value, "dot total")
text(count, 40, 155+posy);
text(nf(interest, 0, 2), 110, 155+posy);
text(nf(principal, 0, 2), 190, 155+posy);
text(nf(unpaid, 0, 2), 290, 155+posy);
text(nf(totalInterest, 0, 2), 430, 155+posy);
count++;///////UPDATE//////////
posy=posy+30;////////POSITION Y//////////
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น