วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558

Lab 4 : Loan Payment

 
void setup(){
  size(500,600);
  textSize(15);
  background(0);
 
  loan_money(5000,12,1);
}
void loan_money(float amount, float rate, int year){
  int month = year*12;
  float per = (rate/100)/month;
  float paymentAmount = amount*(per/(1-pow(1+per,-month)));
  float principal = paymentAmount;
  float unpaid = amount;
  float total = 0;
  int count = 1;
  int y=0;
 
  textAlign(LEFT);
  text("Num.",20,50);
  text("Interest",100,50);
  text("Principal",200,50);
  text("Unpaid",300,50);
  text("Interest total",380,50);
 
  //textAlign(CENTER);
 
 
  while(count <= month){
    text(nf(count, 2),30,100+y); //Num
    text(nf(per*unpaid, 2, 2),100,100+y); //Interest
    total+=per*unpaid;
    principal=paymentAmount-(per*unpaid);
    unpaid =unpaid-principal;
   
    if(unpaid < 0){
      unpaid = 0;
    }
    text(nf(principal, 3, 2),200,100+y); //Principal
    text(nf(unpaid, 4, 2),300,100+y); //Unpaid
    text(nf(total, 3, 2),400,100+y); //Total
   
    count++;
    y+=40;
  }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น