Building Software Systems I & II
&
Computer Fundamentals
By Thakdanai Khunsaen
OS : Ubuntu GNOME 17.04 64-bit
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
Lab3-Delivery Charge
int space = 50;
void setup() {
size(650, 300);
background(#DDFFFF);
int x =50, y =50;
int packageType = 2;
int serviceType = 3;
float weight = 16;
fill(0);
textSize(40);
text("Expressimo Delivery Service", x, y);
charge(x+space, y+space, packageType, serviceType, weight);
}
void charge(int x, int y, int package_type, int service_type, float weight) {
float cost =0;
fill(#FF0000);
textSize(30);
if (package_type == 1) {
text("Package : LETTER", x, y);
if (service_type == 1) {
text("Service : Next day Priority", x, y+space);
if (weight <= 8) {
cost = 12;
} else {
cost = 0;
}
} else if (service_type == 2) {
text("Service : Next day Standard", x, y+space);
if (weight <= 8) {
cost = 10.5;
} else {
cost = 0;
}
} else if (service_type == 3) {
text("Service : No Service", x, y+space);
} else {
text("Service : ERROR", x, y+space);
}
text("Weight : "+weight+" Oz", x, y+space*2);
} else if (package_type == 2) {
text("Package : BOX", x, y);
if (service_type == 1) {
text("Service : Next day Priority", x, y+space);
if (weight <= 1) {
cost = 15.75;
} else {
cost = cal_service1(weight);
}
} else if (service_type == 2) {
text("Service : Next day Standard", x, y+space);
if (weight <= 1) {
cost = 13.75;
} else {
cost = cal_service2(weight);
}
} else if (service_type == 3) {
text("Service : Two-days", x, y+space);
if (weight <= 1) {
cost = 7.00;
} else {
cost = cal_service3(weight);
}
} else {
text("Service : ERROR", x, y+space);
}
text("Weight : "+weight+" Pound", x, y+space*2);
} else {
text("Package : ERROR", x, y);
}
text("Charge : $"+cost, x, y+space*3);
}
float cal_service1(float weight) {
float priority_charge;
float firstCharge = 15.75;
priority_charge = firstCharge + ((weight-1)*1.25);
return priority_charge;
}
float cal_service2(float weight) {
float standard_charge;
float firstCharge = 13.75;
standard_charge = firstCharge + ((weight-1)*1);
return standard_charge;
}
float cal_service3(float weight) {
float twodays_charge;
float firstCharge = 7.00;
twodays_charge = firstCharge + ((weight-1)*0.5);
return twodays_charge;
}
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น