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

LAB 3 Service

void setup() {
  size(800, 500);
}


void draw() {
  background(0);
  frameRate(5);
  drawText(50, 50);
}

// make function draw text
void drawText(int X, int Y) {
  textSize(20);
  fill(255);
  text("                                       Welcome", X, Y);
  text("For Choice a type of package please pressed B for Box or L for Letter ", X, Y+50);
  text("For Choice a type of service please pressed P for next day priority", X, Y+100);
  text("S for next day standard , 2 for 2-day", X, Y+150);
  text("For Choice a Weight of package please pressed  + or - (Oz)", X, Y+200);
  typePackage(choicePackage(), X, Y);
  typeService(choiceService(), X, Y);
  weight(oz(), X, Y);
  expenses(weightOz, X, Y, expenbox(valueOz(weightOz)));
}

// make function for draw text of type package your choice
void typePackage(int choicePackage, int X, int Y) {
  fill(255, 0, 0);
  switch(choicePackage) {
  case 1:
    text(" You TypePackage is Box", X, Y+250);
    break;
  case 2:
    text(" You TypePackage is Letter", X, Y+250);
    break;
  case 0:
    text(" Please press a choice of package type ", X, Y+250);
    break;
  }
}
//set base value
int choiceP =0;
int choiceS =0;
int weightOz =16;

//make function for choice weight oz
void weight(float oz, int X, int Y) {
  fill(0, 150, 200);
  text(" You weight choice is (oz) "+oz, X, Y+350);
}

//make function for up and down value of weight
float oz() {
  if (keyPressed) {
    if (key=='+') {
      weightOz++;
    }
    if (key=='-') {
      if (weightOz>0) {
        weightOz--;
      }
    }
  }
  return weightOz;
}

// make function for setup value typepackage
int choicePackage() {
  if (key=='B'||key =='b') {
    choiceP=1;
  }
  if (key=='L'||key=='l') {
    choiceP=2;
  }

  return choiceP;
}

// make function for draw text of type service your choice
void typeService(int choiceService, int X, int Y) {
  fill(0, 200, 0);
  switch(choiceService) {
  case 1:
    text(" You TypePackage is Next Day Priority", X, Y+300);
    break;
  case 2:
    text(" You TypePackage is Next Day Standard", X, Y+300);
    break;
  case 3:
    text(" You TypePackage is 2-Day ", X, Y+300);
    break;
  case 0:
    text(" Please press a choice of service type ", X, Y+300);
    break;
  }
}

// make function for setup value typepackage
int choiceService() {
  if (key=='P'||key =='p') {
    choiceS=1;
  }
  if (key=='S'||key=='s') {
    choiceS=2;
  }
  if (key=='2') {
    choiceS=3;
  }

  return choiceS;
}

//transform oz to pound
float valueOz(float oz) {
  float pound;
  pound=oz/16;
  return pound;
}


//set print text of expenses
void expenses(float oz, int X, int Y, float expenBox) {
  fill(150, 150, 0);
  //set for letter
  if ((choiceP==2&&choiceS==1)&&oz<=8.00) {
    text("You expenses is $ 12.00", X, Y+400);
  }
  if ((choiceP==2&&choiceS==2)&&oz<=8.00) {
    text("You expenses is $ 10.50", X, Y+400);
  }
  if ((choiceP==2&&choiceS==3)&&oz<=8.00) {
    text("That not available", X, Y+400);
  }
  if (choiceP==2&&oz>8.00) {
    text("Cant use this service", X, Y+400);
  }
  // set for box

  if (choiceP==1&&oz>=16) {
    text("You expenses is $ "+expenBox, X, Y+400);
  } else {
    if (choiceP==1&&choiceS==1) {
      text("You expenses is $ 15.75", X, Y+400);
    } else {
      if (choiceP==1&&choiceS==2) {
        text("You expenses is $ 13.75", X, Y+400);
      } else {
        if (choiceP==1&&choiceS==3) {
          text("You expenses is $ 7", X, Y+400);
        }
      }
    }
  }
}



//set value of expensesbox
float expenbox(float weightPound) {
  float expenbox=0;
  if (choiceS==1) {
    expenbox = 15.75 + ((weightPound-1)*1.25);
  }
  if (choiceS==2) {
    expenbox = 13.75 + ((weightPound-1));
  }
  if (choiceS==3) {
    expenbox = 7 + ((weightPound-1)*0.5);
  }
  return expenbox;
}

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

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