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

Lab4-Lone

void setup() {
  size(850, 600);
  background(0);
  int year = 1;
  calLone(5000,0.12,year);
  draw_text(year);
}
void calLone(float beginBalance, float interestRate, int year) {
  int x = 430;
  int y = 400;

  int month = year*12;
  float IRPM = interestRate/month;//interest rate per month
  float paypermonth = beginBalance*(IRPM/(1-pow(1+IRPM, -month)));
  float interest = 0;
  float principal = 0;
  float endingBalance = 0;
  int n = 1;

  while (n<=month) {
    interest = IRPM*beginBalance;
    principal = paypermonth - interest;
    endingBalance = beginBalance - principal;
 
    textSize(30);
    text(nf(+beginBalance,3,1),x-300,y-300);
    text(nf(+interest,2,1),x-100,y-300);
    text(nf(+principal,3,1),x+50,y-300);
    text(nf(+endingBalance,3,1),x+220,y-300);
    beginBalance = endingBalance;
    y+=40;
    n+=1;
  }
}

void draw_text(int year){
  int x = 430;
  int y = 400;
  int n = 1;
  int month = year*12;

  text("Begin Balance",x-350,y-350);
  text("interest",x-130,y-350);
  text("principal",x+20,y-350);
  text("Ending balance",x+160,y-350);

  while(n<=month){
    text(+n,x-370,y-300);
    y+=40;
    n++;
  }

}

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

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