วันอาทิตย์ที่ 25 สิงหาคม พ.ศ. 2556

=if-else=(Hard)

Programming Exercise
Proposition => For employees who work more than 40 hours per week, calculate overtime pay and add it to their regular pay
  Regular pay = 20$/hours
  Overtime wages = 25$/hours

Translated into Thailand => สำหรับพนักงานที่ทำงานมากกว่า 40 ชั่วโมงต่อสัปดาห์ ให้คำนวณค่านอกเวลาและรวมกับค่าจ้างปกติของพวกเขา
 ค่าจ้างเวลาปกติ = 20$/ชั่วโมง
 ค่าจ้างนอกเวลา =  25$/ชั่วโมง
Solution=>  
  int work= 45;
  int regular=0;
  int over=0;
  int stan=40;
  int sum;
  if(work>stan){                     //เมื่อเงื่อนไขwork>stanเป็นจริงจะทำตามคำสั่งด้านใน
    over=(work-stan)*25;      //คำนวนหาค่าจ้างที่เกินเวลามา
    regular=stan*20;              //คำนวนหาเงินค้าจ้างในเวลาปกติ
  }
  else{
    regular=work*20;
  }
  sum=regular+over;
  println("Wage="+sum+"$");

Out put => Wage = 925 $

You can run code in http://processingjs.org/tools/processing-helper.html


text book name :Programming and problem solving with Java – 2nd edition
Author : Nell Dale and Chip Weems
              ISBN 978-0-7637-3402-2

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

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