วันเสาร์ที่ 5 กันยายน พ.ศ. 2558

LAB 3 Generic 1-4


Lab 3 Generic 1 (Grade Calculation Program)
    void setup(){
      int score = 80;
      grade_Calculate(score);
      }

    void grade_Calculate(int score){
      println("*******Grade Calculation Program*******");
      println("score = "+score);
      print("Grade : ");
      if(score >= 80){
        println("A");
      }else if(score >= 70){
        println("B");
      }else if(score >= 60){
        println("C");
      }else if(score >= 45){
        println("D");
      }else{
        println("F");
        }
      println("***************************************");
      }

Lab 3 Generic 2 (Power Of Ten)
    void setup(){
      float number = 2*pow(10,21);
      power_of_ten(number);
      }

    void power_of_ten(float number){
      println("*************Power of ten**************");
      println("Value = "+number);
      print("Power of 10 = ");
      if(number >= 1.0e30){
        println("30");
        println("Number : Nonillion");
      }else if(number >= 1.0e21){
        println("21");
        println("Number : Sextillion");
      }else if(number >= 1.0e18){
        println("18");
        println("Number : Quintillion");
      }else if(number >= 1.0e15){
        println("15");
        println("Number : Quadrillion");
      }else if(number >= 1.0e12){
        println("12");
        println("Number : Trillion");
      }else if(number >= 1.0e9){
        println("9");
        println("Number : Billion");
      }else if(number >= 1.0e6){
        println("6");
        println("Number : Million");
        }
      println("***************************************");
      }

Lab 3 Generic 3 (Leap Year)
    void setup(){
      int year = 1952;
      leap_year(year);
      }

    void leap_year(int year){
      println("*************Leap Year*****************");
      println("Year = "+year);
      if( (year%4 == 0 && !(year%100 == 0) ) || (year%400 == 0) ){
        println("Leap Year");
      }else{
        println("Not a Leap Year");
        }
      println("***************************************");
      }

Lab 3 Generic 4 (Delivery Charge)
    void setup(){
      int typePackage = 1;
      int typeService = 1;
      float weight = 8.00;
      delivery_charge(typePackage,typeService,weight);
      }
      
    void delivery_charge(int typePackage,int typeService,float weight){
      float cost = 0.00;boolean errorCost = false;
      println("*************Expressimo Delivery Service*****************");
      println("*******************Delivery Charge***********************");
      println(" Type Of Package | Type Of Service             ");
      println(" 1) Letter (1)   | 1) Next Day Priority (1)    ");
      println(" 2) Box (2)      | 2) Next Day Standard (2)    ");
      println("                 | 3) 2-Day (3)                ");
      println("");
      if(typePackage == 1){
        println("Type Of Package : Letter");
      }else if(typePackage == 2){
        println("Type Of Package : Box");
      }else{
        println("Type Of Package : error");      
      }
      if(typeService == 1){
        println("Type Of Service : Next Day Priority");
      }else if(typeService == 2){
        println("Type Of Service : Next Day Standard");
      }else if(typeService == 3){
        println("Type Of Service : 2-Day");
      }else{
        println("Type Of Service : error");
        }
      print("Weight : "+weight);    
      if(typePackage == 1){
        println(" oz");
        if(typeService == 1) cost = 12.00;
        if(typeService == 2) cost = 10.50;
        if(typeService == 3 || weight > 8.00) errorCost = true;
         }
      if(typePackage == 2){
        println(" pound");
        if(typeService == 1){
          if(weight <= 1){
            cost = 15.75;
          }else{
            cost = 15.75+((weight-1)*1.25);
            }
          }
        if(typeService == 2){
          if(weight <= 1){
            cost = 13.75;
          }else{
            cost = 13.75+((weight-1)*1.00);
            }
          }
        if(typeService == 3){
          if(weight <= 1){
            cost = 7.00;
          }else{
            cost = 7.00+((weight-1)*0.5);
            }
          }
      }
        if(errorCost){
          println("Cost : Service not alivable");
        }else{
          println("Cost : $"+cost);
          }
      println("*********************************************************");  
      }

ปัญหาที่พบและวิธีแก้ :
  1) ไม่มีเครื่องหมายเมื่อจบบรรทัดคำสั่ง ; (เติมเครื่องหมาย ; หลังคำสั่งนั้น)
  2) ไม่มีวงเล็บ } (เติมวงเล็บ } ให้ครบ)
  3) ชื่อตัวแปรที่ใช้งานไม่ตรงกับที่ตัวแปรที่กำหนดไว้ (เปลี่ยนตัวแปรให้ตรงกับที่กำหนดไว้)
  4)  Generic 4 เมื่อใส่น้ำหนักจดหมายเกิน 8 oz ยังสามารถแสดงราคาได้ (เพิ่มเงื่อนไขให้โปรแกรมไม่คำนวณราคาเมื่อน้ำหนักจดหมายเกิน)

        

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

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