Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("請輸入身高 (公尺) :");
            string inputHeight = Console.ReadLine();

            Console.WriteLine("請輸入體重 (公斤) :");
            string inputWeight = Console.ReadLine();

            Console.WriteLine("你是公的嗎?(請輸入y/n)");
            String genderIdent = Console.ReadLine();

            BMIService.IBodyMeasureIndex bmiService = null;
            bmiService = new BMIService.WomenBodyMeasureIndex();
            double bmi = 0.0d;


            bool isMale = true;

            isMale = (genderIdent == "y");

            if (isMale)
            {
                bmiService = new MenBodyMeasureIndex();
            }
            else
            {
                bmiService = new WomenBodyMeasureIndex();
            }


            double height = double.Parse(inputHeight);
            double weight = double.Parse(inputWeight);


            MeasureResult result = bmiService.caculute(height, weight, out bmi);

            Console.WriteLine(bmi);


            switch (result)
            {
            case MeasureResult.Less:
                Console.WriteLine("太瘦");
                break;

            case MeasureResult.Normal:
                Console.WriteLine("剛剛好");
                break;

            case MeasureResult.More:
                Console.WriteLine("尼太胖!!!");
                break;
            }


            Console.ReadLine();
        }
        public async Task<string> Men()
        {
            var forms = await Request.Content.ReadAsFormDataAsync();

            double height = Convert.ToDouble(forms["height"]);
            double weight = Convert.ToDouble(forms["weight"]);

            IBodyMeasureIndex bmiService = new MenBodyMeasureIndex();
            double bmi = 0.0d;
            MeasureResult result = bmiService.Calculate(height, weight, out bmi);

            switch (result)
            {
                case MeasureResult.Less:
                    return "太瘦";
                case MeasureResult.More:
                    return "太胖";
                case MeasureResult.Normal:
                    return "剛好";
                default:
                    return "";
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("請輸入身高 (公尺):");
            string heightInput = Console.ReadLine();

            Console.WriteLine("請輸入體重 (公斤):");
            string weightInput = Console.ReadLine();

            Console.WriteLine("你是公的嗎? (請輸入y/n):");
            string genderIdent = Console.ReadLine();

            double height = 0.0d;

            if (!double.TryParse(heightInput, out height))
            {
                Console.WriteLine("你輸入的不是數字。");
                Console.ReadLine();
                return;
            }

            double weight = 0.0d;

            if (!double.TryParse(weightInput, out weight))
            {
                Console.WriteLine("你輸入的不是數字。");
                Console.ReadLine();
                return;
            }

            double bmi    = 0.0d;
            bool   isMale = true;

            isMale = (genderIdent == "y");

            IBodyMeasureIndex bmiService = null;

            if (isMale)
            {
                bmiService = new MenBodyMeasureIndex();
            }
            else
            {
                bmiService = new WomenBodyMeasureIndex();
            }

            MeasureResult result = bmiService.Calculate(height, weight, out bmi);

            Console.WriteLine("BMI: {0}", bmi);
            Console.WriteLine("BMI Formatted: {0:0.00}", bmi);

            switch (result)
            {
            case MeasureResult.Less:
                Console.WriteLine("太瘦");
                break;

            case MeasureResult.More:
                Console.WriteLine("太胖");
                break;

            case MeasureResult.Normal:
                Console.WriteLine("剛好");
                break;
            }

            Console.ReadLine();
        }