วันเสาร์ที่ 26 มีนาคม พ.ศ. 2554

วิเคราะห์งาน โฟลว์ชาร์ต และโปรแกรมด้วยภาษาจาวา

โปรแกรมคำนวนหาน้ำหนักมาตรฐาน
*********************************************************
วิเคราะห์งาน
1.สิ่งที่โจทย์ต้องการ คำนวนหาน้ำหนักมาตรฐาน ของชาย/หญิง 
2.ผลลัพท์
Input your name : _______
Input your gender F,f or M,m : _______
Input your height : _______
Input your weigth : _______
Your are Name : _______
You are  Male : _______
Your height is : _______
Your weight is : _______
Your std-weight is : _______
Now you are _______


3.สิ่งที่โจทย์ให้มา 
ชื่อ เพศ ส่วนสูง น้ำหนัก น้ำหนักมาตรฐาน รูปร่าง


4.ตัวแปร 
height =ส่วนสูง
weigth =น้ำหนัก
stdweight =น้ำหนักมาตรฐาน
Name =ชื่อ
gender =เพศ


5.วิธีการ
1.เริ่มการทำงาน
2.กำหนดตัวแปร int height,weight=0,stdweight=0/char gender/String data,String name
3.แสดงผล Input your name
4.แสดงผล Input your gender F,f or M,m : 
5. เงื่อนไบ ถ้า ((gender=='M')||(gender=='m')||(gender=='F')||(gender=='f')) 
Yใช่ทำข้อ6 ,9
Nไม่ใช่ทำข้อ10
6.เงื่อนไบ ถ้า((gender=='F')||(gender=='f'))
แสดง Input your heigth
แสดง Input your weigth
รับค่า weigth
Y ให้ stdweigth=heigth-110
N ทำต่อข้อ7
7.เงื่อนไข ถ้า(weigth>(stdweigth+5))
ให้แสดง
Your are Name
                  You are  Female
                  Your heigth is :
                  Your weigth is :
                  Your std-weigth is :
                  Now you are Fat
เงื่อนไข ถ้า(weigth>(stdweigth-5))
ให้แสดง
Your are Name
                  You are  Female
                  Your heigth is :
                  Your weigth is :
                  Your std-weigth is :
                  Now you are Thin
เงื่อนไข ถ้า(weigth==(stdweigth))
ให้แสดง
Your are Name
                  You are  Female
                  Your heigth is :
                  Your weigth is :
                  Your std-weigth is :
                  Now you are Standard:
8.เงื่อนไบ ถ้า((gender=='M')||(gender=='m'))
แสดง Input your heigth
แสดง Input your weigth
รับค่า weigth
Y ให้ stdweigth=heigth-100
N ทำต่อข้อ 9
9.เงื่อนไข ถ้า(weight>(stdweight+5))
ให้แสดง
Your are Name
                  You are  Male
                  Your height is :
                  Your weight is :
                  Your std-weight is :
                  Now you are Fat
เงื่อนไข ถ้า(weight>(stdweight-5))
ให้แสดง
Your are Name
                  You are  Male
                  Your height is :
                  Your weight is :
                  Your std-weight is :
                  Now you are Thin
เงื่อนไข ถ้า(weight==(stdweight))
ให้แสดง
Your are Name
                  You are  Male
                  Your height is :
                  Your weight is :
                  Your std-weight is :
                  Now you are Standard:
10.แสดงYour gender is :
           Invalid dender
           M or m For Male F or f For Female
11.จบการทำงาน



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
โฟลว์ชาร์ต


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


โปรแกรม


import java.io.*;//แบบตายตัวของโปรแกรมรับค่าและแสดงผล
class Ja_janjiraIT//ชื่อคลาสJa_janjiraIT
{
 public static void main(String[] args) throws IOException//แบบตายตัวของโปรแกรมรับค่าและแสดงผล
 {
  int height=0;//กำหนดตัวแปร height ชนิดตัวเลขมีค่าเป็น0
  int weight=0;//กำหนดตัวแปร weight ชนิดตัวเลขมีค่าเป็น0
  int stdweight=0;//กำหนดตัวแปร stdweight ชนิดตัวเลขมีค่าเป็น0
  char gender;//กำหนดตัวแปร gender ชนิดตัวอักษร
  BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));//แบบตายตัวของโปรแกรมรับค่า
  String data;//กำหนดตัวแปร data ชนิดตัวอักษร
  String name;//กำหนดตัวแปร name ชนิดตัวอักษร
  System.out.print("Input your name : "); //แสดง("Input your name : ")
  name = stdin.readLine(); //กำหนดตัวแปร name มีค่าเท่ากับค่าที่รับมา
  {
  System.out.print("Input your gender F,f or M,m : "); //แสดง("Input your gender F,f or M,m : ")
data = stdin.readLine(); //กำหนดตัวแปร data มีค่าเท่ากับค่าที่รับมา

  if (data.equals(""))  //equals เป็นเมทธอดที่อยู่ใน String กำหนดให้ตัวแปรdataเรียกใช้ใน" "
  {
   System.out.print("Error Input your gender F,f or M,m ,Please: "); //แสดงค่า"Error Input your gender F,f or M,m ,Please: "
  }
  else
  {
   gender=data.charAt(0);
 
   if ((gender=='M')||(gender=='m')||(gender=='F')||(gender=='f')) //กำหนดให้genderเท่ากับM ||genderเท่ากับm ||genderเท่ากับF|| genderเท่ากับf ||
   {
    if ((gender=='F')||(gender=='f')) //กำหนดให้genderเท่ากับF|| genderเท่ากับf
    {
      data=" "; //กำหนดให้dataเท่ากับ" "
      System.out.print("Input your height : "); //แสดง Input your height
      data = stdin.readLine(); //กำหนดตัวแปร data มีค่าเท่ากับค่าที่รับมา
      {
       height=Integer.parseInt(data); //ให้ค่าdata ที่รับมาเป็นชนิดตัวอักษรเท่ากับค่าheightชนิดตัวเลข
       data=" ";//กำหนดให้dataเท่ากับ" "
       System.out.print("Input your weigth : "); //แสดง Input your weight
               data = stdin.readLine(); //กำหนดตัวแปร data มีค่าเท่ากับค่าที่รับมา
       {
        weight=Integer.parseInt(data); //ให้ค่าdata ที่รับมาเป็นชนิดตัวอักษรเท่ากับค่าweightชนิดตัวเลข
        stdweight=height-110; //กำหนดให้stdweightเท่ากับheightลบ110
        if (weight>(stdweight+5)) //กำหนดให้weightมากกว่าstdweightบวก5
        {
        System.out.print("Hello !!  "+name + "\n" +
                      "You are  Female" + "\n" +
                      "Your height is : " + height + "\n" +
                      "Your weight is : " + weight + "\n" +
                      "Your std-weight is : " + stdweight + "\n" +
                      "Now you are Fat"); // ให้แสดงผลHello !! name"You are  Female""Your height is : " "Your weight is : "  "Your std-weight is : " "Now you are Fat"
        }
        else
            if (weight<(stdweight-5)) //กำหนดให้weightน้อยกว่าstdweightลบ5
        {
         System.out.print("Hello !! "+name + "\n" +
                      "You are  Female" + "\n" +
                      "Your height is : " + height + "\n" +
                      "Your weight is : " + weight + "\n" +
                      "Your std-weight is : " + stdweight + "\n" +
                      "Now you are Thin"); //ให้แสดงHello !! name"You are  Female""Your height is : " "Your weight is : "  "Your std-weight is : " "Now you are Thin"
        }
        else
        {
         System.out.print("Hello !! "+name + "\n" +
                      "You are  Female" + "\n" +
                      "Your height is : " + height + "\n" +
                      "Your weight is : " + weight + "\n" +
                      "Your std-weight is : " + stdweight + "\n" +
                      "Now you are standard"); //ให้แสดงHello !! name "You are  Female" "Your height is : " "Your weight is : "  "Your std-weight is : " "Now you are standard"
        }
       }
      }
    }
    else
    if ((gender=='M')||(gender=='m'))//กำหนดให้genderเท่ากับM|| genderเท่ากับm
    {
      data=" "; //กำหนดให้dataเท่ากับ" "
      System.out.print("Input your height : "); //แสดงผล Input your height
              data = stdin.readLine(); //กำหนดตัวแปร data มีค่าเท่ากับค่าที่รับมา
      {
       height=Integer.parseInt(data); //ให้ค่าdata ที่รับมาเป็นชนิดตัวอักษรเท่ากับค่าheightชนิดตัวเลข
       data=" ";//กำหนดให้dataเท่ากับ" "
       System.out.print("Input your weigth : "); //แสดงผล Input your weight
               data = stdin.readLine();//กำหนดตัวแปร data มีค่าเท่ากับค่าที่รับมา
       {
        weight=Integer.parseInt(data); //ให้ค่าdata ที่รับมาเป็นชนิดตัวอักษรเท่ากับค่าweightชนิดตัวเลข
        stdweight=height-100; //กำหนดให้stdweightเท่ากับheightลบ100
       
        if (weight>(stdweight+5))//กำหนดให้weightมากกว่าstdweightบวก5
        {
         System.out.print("Hello !! "+name + "\n" +
                      "You are  Male" + "\n" +
                      "Your height is : " + height + "\n" +
                      "Your weight is : " + weight + "\n" +
                      "Your std-weight is : " + stdweight + "\n" +
                      "Now you are Fat"); // ให้แสดงผลHello !! name"You are  Male""Your height is : " "Your weight is : "  "Your std-weight is : " "Now you are Fat"
        }
        else if (weight<(stdweight-5)) //กำหนดให้weightน้อยกว่าstdweightลบ5
        {
        System.out.print("Hello !! "+name + "\n" +
                      "You are  Male" + "\n" +
                      "Your height is : " + height + "\n" +
                      "Your weight is : " + weight + "\n" +
                      "Your std-weight is : " + stdweight + "\n" +
                      "Now you are Thin");// ให้แสดงผลHello !! name"You are  Male""Your height is : " "Your weight is : "  "Your std-weight is : " "Now you are Thin"
        }
        else
        {
        System.out.print("Hello !! "+name + "\n" +
                      "You are  Male" + "\n" +
                      "Your height is : " + height + "\n" +
                      "Your weight is : " + weight + "\n" +
                      "Your std-weight is : " + stdweight + "\n" +
                      "Now you are standard"); // ให้แสดงผลHello !! name"You are  Male""Your height is : " "Your weight is : "  "Your std-weight is : " "Now you are standard"
        }
       }
      }
    }
   }
   else
   {
   System.out.print("Your gender is : " + gender + "\n" +
                  "Error gender" + "\n" +
                  "M or m For Male"+ "\n" +
                  "F or f For Female"); //ให้แสดงผลYour gender is"You are  Male""Error gender" "M or m For Male "  "F or f For Female "
   }
  }
  }
 }
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

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