วันจันทร์ที่ 1 กันยายน พ.ศ. 2557
EX 1 : Task#3 - Tax Calculator
byte i;
long income;
double tax,total;
double ft0,ft1,ft2,ft3,ft4,ft5,ft6,t;
void setup()
{
size(500,100);
}
void draw()
{
size(500,100);
background(0);
fill(0);
textSize(15);
fill(20,255,20);
input_income();
print_income();
cal_tax();
print_tax();
}
void input_income()
{
if(i==0)
{
if(keyPressed)
{
if(key == 48) {income = income*10+0;i=1;}
if(key == 49) {income = income*10+1;i=1;}
if(key == 50) {income = income*10+2;i=1;}
if(key == 51) {income = income*10+3;i=1;}
if(key == 52) {income = income*10+4;i=1;}
if(key == 53) {income = income*10+5;i=1;}
if(key == 54) {income = income*10+6;i=1;}
if(key == 55) {income = income*10+7;i=1;}
if(key == 56) {income = income*10+8;i=1;}
if(key == 57) {income = income*10+9;i=1;}
}
}
}
void keyPressed()
{
if(keyCode==BACKSPACE)
{
reset();
}
}
void keyReleased()
{
i=0;
}
void cal_tax()
{
ft0=150000*0.00;
ft1=150000*0.05;
ft2=200000*0.10;
ft3=250000*0.15;
ft4=250000*0.20;
ft5=1000000*0.25;
ft6=2000000*0.30;
if (income>4000000) {t=(income-4000000)*0.35; tax=t+ft0+ft1+ft2+ft3+ft4+ft5+ft6;}
else if (income>2000000) {t=(income-2000000)*0.30; tax=t+ft0+ft1+ft2+ft3+ft4+ft5;}
else if (income>1000000) {t=(income-1000000)*0.25; tax=t+ft0+ft1+ft2+ft3+ft4;}
else if (income >750000) {t=(income-750000) *0.20; tax=t+ft0+ft1+ft2+ft3;}
else if (income >500000) {t=(income-500000) *0.15; tax=t+ft0+ft1+ft2;}
else if (income >300000) {t=(income-300000) *0.15; tax=t+ft0+ft1;}
else if (income >150000) {t=(income-150000) *0.05; tax=t+ft0;}
else {t=(income) *0.00; tax=t;}
}
void print_income()
{
if(income>29000000){text("Error : Income out of range(max 29000000)", 20, 40);}
else{text("Please input your income here(max 29000000) = "+income, 20, 40);}
}
void print_tax()
{
if(income>29000000){text("Tax = N/A", 20, 70);}
else{text("Tax = "+tax, 20, 70);}
}
void reset()
{
income=0;
i=0;
tax=0;
total=0;
ft0=0;
ft1=0;
ft2=0;
ft3=0;
ft4=0;
ft5=0;
ft6=0;
t=0;
}
EX 1 : Task#2 - Quadrant Check
void setup(){
background(255);
size(500,500);
textAlign(CENTER);
}
void draw()
{
background(255);
fill(255);
strokeWeight(8);
rect(0,0,width,height);
strokeWeight(5);
line(0,height/2, width,height/2);
line(width/2,0, width/2, height);
if(mouseX > width/2 && mouseY < height/2)
{fill(150);rect(width/2,0,width/2,height/2);fill(0);text("Quadrant 1", width*3/4,height/4);}
else if(mouseX < width/2 && mouseY < height/2)
{fill(150);rect(0,0,width/2,height/2);fill(0);text("Quadrant 2",width*1/4,height/4);}
else if(mouseX < width/2 && mouseY > height/2)
{fill(150);rect(0,height/2,width/2,height/2);fill(0);text("Quadrant 3",width*1/4,height*3/4);}
else
{fill(150);rect(width/2,height/2,width/2,height/2);fill(0);text("Quadrant 4",width*3/4,height*3/4);}
}
EX 1 : Task#1 - Grade Calculator
int score,i;
String grade;
void setup()
{
size(300,100);
score = 0;
i = 0;
}
void draw()
{
size(300,100);
background(0);
fill(0);
textSize(15);
fill(20,255,20);
input_score();
print_score();
cal_grade();
print_grade();
if(score>=1000){reset();}
}
void input_score()
{
if(i==0)
{
if(keyPressed)
{
if(key == 48) {score = score*10+0;i=1;}
if(key == 49) {score = score*10+1;i=1;}
if(key == 50) {score = score*10+2;i=1;}
if(key == 51) {score = score*10+3;i=1;}
if(key == 52) {score = score*10+4;i=1;}
if(key == 53) {score = score*10+5;i=1;}
if(key == 54) {score = score*10+6;i=1;}
if(key == 55) {score = score*10+7;i=1;}
if(key == 56) {score = score*10+8;i=1;}
if(key == 57) {score = score*10+9;i=1;}
}
}
}
void keyPressed()
{
if(keyCode==BACKSPACE)
{
reset();
}
}
void keyReleased()
{
i=0;
}
void print_score()
{
text("Please input your score here = "+score, 20, 40);
}
void cal_grade()
{
if (score >=80) {grade = "A" ;}
else if (score >= 75 && score < 80) {grade = "B+";}
else if (score >= 70 && score < 75) {grade = "B" ;}
else if (score >= 65 && score < 70) {grade = "C+";}
else if (score >= 60 && score < 65) {grade = "C" ;}
else if (score >= 55 && score < 60) {grade = "D+";}
else if (score >= 50 && score < 55) {grade = "D" ;}
else {grade = "F" ;}
}
void print_grade()
{
if (score > 100) {text("Error : your score is more than 100", 20, 72);}
else {text("Your grade is "+grade, 20, 70);}
}
void reset()
{
score = 0;
i = 0;
}
สมัครสมาชิก:
บทความ (Atom)