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

Lab3-service charge

void setup() {
  size(600, 400);
  background(#cc3333);
  textSize(30);
  text("Expressimo Delivery Service", width/10, height/10);
  text("type of package is", width/50+10, height/2-90);
  text("type of service is", width/50+10, height/2-50);
  serviceCharge(2,1,20);
}
//Choose Type of package 1=Letter,2=Box
//Choose Type os service 1=Next Day Priority,2=Next Day Standard,3=Two-Day
void serviceCharge(int typeOfPackage, int typeOfService, float weightOfPackage ) {
  float cost = 0;
  if (typeOfPackage==1) {
    text("Letter", width/50+280, height/2-90);
  } else if (typeOfPackage==2) {
    text("Box", width/50+280, height/2-90);
  } else {
    text("Not found", width/50+280, height/2-90);
  }
  if (typeOfService==1) {
    text("Next Day Priority", width/50+270, height/2-50);
  } else if (typeOfService ==2) {
    text("Next Day Standard", width/50+270, height/2-50);
  } else if (typeOfService ==3) {
    text("Two-Day", width/50+270, height/2-50);
  } else {
    text("Not found", width/50+270, height/2-50);
  }
  if (typeOfPackage == 1) {
    text("oz.", width/2+340, height/2-10);
    if (typeOfService == 1 && weightOfPackage <= 8)
      cost = 12;
    if (typeOfService == 2 && weightOfPackage <= 8)
      cost = 10;
    if (typeOfService >= 3 || weightOfPackage > 8)
    text("'No Services'", 230, height/2+110);
  }

  if (typeOfPackage  == 2) {
    text("pound.", width/2+130, height/2-10);
    if (typeOfService == 1) {
      if (weightOfPackage <= 1)
        cost = 15.75;
      else if (weightOfPackage > 1) {
        cost = calServicePriority(weightOfPackage);
      }
    } else if (typeOfService == 2) {
      if (weightOfPackage <= 1)
      cost = 13.75;
      else if (weightOfPackage > 1) {
        cost = calServiceStandard(weightOfPackage);
      }
    } else if (typeOfService == 3) {
      if (weightOfPackage <= 1)
      cost = 7.00;
      else if (weightOfPackage > 1) {
        cost = calServiceTwodays(weightOfPackage);
      }
    }
  }
  text("Weight of Package :  "+weightOfPackage, width/50+10, height/2-10);
  text("Charge : "+"$ "+cost, width/50+10, height/2+30);
}

float calServicePriority(float weightOfPackage) {
  float priorityCharge;
  float firstCharge = 15.75;
  priorityCharge = firstCharge + ((weightOfPackage-1)*1.25);
  return priorityCharge;
}

float calServiceStandard(float weightOfPackage) {
  float standardCharge;
  float firstCharge = 13.75;
  standardCharge = firstCharge + ((weightOfPackage-1)*1.00);
  return standardCharge;
}

float calServiceTwodays(float weightOfPackage) {
  float twodaysCharge;
  float firstCharge = 7.00;
  twodaysCharge = firstCharge + ((weightOfPackage-1)*0.50);
  return twodaysCharge;
}

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

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