コード例 #1
0
ファイル: StartUp.cs プロジェクト: Dimitvp/C-Sharp-OOP-Basics
        static void Main(string[] args)
        {
            var personName = string.Empty;
            var personAge  = 0;
            var over30     = new Over30();


            int numOfPeople = int.Parse(Console.ReadLine());

            for (int i = 0; i < numOfPeople; i++)
            {
                var inputTokens = Console.ReadLine().Split(' ').ToArray();
                personName = inputTokens[0];
                personAge  = int.Parse(inputTokens[1]);

                var person = new Person(personName, personAge);
                if (personAge > 30)
                {
                    over30.AddMember(person);
                }
            }

            foreach (var p in over30.Members.OrderBy(m => m.Name))
            {
                Console.WriteLine($"{p.Name} - {p.Age}");
            }
        }
コード例 #2
0
ファイル: StartUp.cs プロジェクト: skorae/SoftUni-kdinev
        static void Main(string[] args)
        {
            Over30 peopleOver30 = new Over30();
            int    n            = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] arr = Console.ReadLine().Split();

                string name = arr[0];
                int    age  = int.Parse(arr[1]);

                Person person = new Person(name, age);
                if (person.Age > 30)
                {
                    peopleOver30.AddPeopleOver30(person);
                }
            }

            foreach (var p in peopleOver30.PeopleOver30.OrderBy(x => x.Name))
            {
                Console.WriteLine($"{p.Name} - {p.Age}");
            }
        }
コード例 #3
0
        private void Calculate_Click(object sender, RoutedEventArgs e)
        {
            Button source  = (Button)sender;
            Image  content = source.Content as Image;

            weight = string.IsNullOrEmpty(InputWeight.Text) ? 1 : double.Parse(InputWeight.Text);
            height = string.IsNullOrEmpty(InputHeight.Text) ? 1 : double.Parse(InputHeight.Text);


            if (Units.IsChecked == true)
            {
                // Converting height from cm into inches, becuz the formula uses inches
                height = height * 0.393701;
                if (InpH == true && InpW == true)
                {
                    BMI1 = 703.0 * (weight / height / height);
                }
                else
                {
                    BMI1 = 0;
                }
            }
            else
            {
                //converting height from feet into meters, becuz the formula uses meters
                height = height * 0.3048;

                if (InpH == true && InpW == true)
                {
                    BMI1 = weight / height / height;
                }
                else
                {
                    BMI1 = 0;
                }
            }
            if (height < 0 || weight < 0)
            {
                MessageBox.Show("Invalid input.", "Information", MessageBoxButton.OK);
                BMI1 = 0;
            }


            if (weight == 0 || height == 0)
            {
                MessageBox.Show("Results will be inaccurate. Weight/ Height is not a valid number.", "Information", MessageBoxButton.OK);
                BMI1 = 0;
            }

            if (BMI1 == 0)
            {
                Under0.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 0 && BMI1 <= 1.5)
            {
                Under1.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 1.5 && BMI1 <= 2.5)
            {
                Under2.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 2.5 && BMI1 <= 3.5)
            {
                Under3.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 3.5 && BMI1 <= 4.5)
            {
                Under4.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 4.5 && BMI1 <= 5.5)
            {
                Under5.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 5.5 && BMI1 <= 6.5)
            {
                Under6.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 6.5 && BMI1 <= 7.5)
            {
                Under7.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 7.5 && BMI1 <= 8.5)
            {
                Under8.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 8.5 && BMI1 <= 9.5)
            {
                Under9.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 9.5 && BMI1 <= 10.5)
            {
                Under10.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 10.5 && BMI1 <= 11.5)
            {
                Under11.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 11.5 && BMI1 <= 12.5)
            {
                Under12.Begin();
                Description.Text = "Underweight";
            }

            else if (BMI1 > 12.5 && BMI1 <= 13.5)
            {
                Under13.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 13.5 && BMI1 <= 14.5)
            {
                Under14.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 14.5 && BMI1 <= 15.5)
            {
                Under15.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 15.5 && BMI1 <= 16.5)
            {
                Under16.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 16.5 && BMI1 <= 17.5)
            {
                Under17.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 17.5 && BMI1 <= 18.5)
            {
                Under18.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 18.5 && BMI1 <= 19.9)
            {
                Under19.Begin();
                Description.Text = "Underweight";
            }
            else if (BMI1 > 19.9 && BMI1 <= 20.5)
            {
                Normal20.Begin();
                Description.Text = "Normal";
            }

            else if (BMI1 > 20.5 && BMI1 <= 21.5)
            {
                Normal21.Begin();
                Description.Text = "Normal";
            }
            else if (BMI1 > 21.5 && BMI1 <= 22.5)
            {
                Normal22.Begin();
                Description.Text = "Normal";
            }
            else if (BMI1 > 22.5 && BMI1 <= 23.5)
            {
                Normal23.Begin();
                Description.Text = "Normal";
            }
            else if (BMI1 > 23.5 && BMI1 <= 24.5)
            {
                Normal24.Begin();
                Description.Text = "Normal";
            }
            else if (BMI1 > 24.5 && BMI1 <= 25)
            {
                Normal25.Begin();
                Description.Text = "Normal";
            }
            else if (BMI1 > 25 && BMI1 <= 26.5)
            {
                Over26.Begin();
                Description.Text = "Overweight";
            }
            else if (BMI1 > 26.5 && BMI1 <= 27.5)
            {
                Over27.Begin();
                Description.Text = "Overweight";
            }
            else if (BMI1 > 27.5 && BMI1 <= 28.5)
            {
                Over28.Begin();
                Description.Text = "Overweight";
            }
            else if (BMI1 > 28.5 && BMI1 <= 29.8)
            {
                Over29.Begin();
                Description.Text = "Overweight";
            }
            else if (BMI1 > 29.8 && BMI1 <= 30.5)
            {
                Over30.Begin();
                Description.Text = "Overweight";
            }
            else if (BMI1 > 30.5 && BMI1 <= 31.5)
            {
                Obese31.Begin();
                Description.Text = "Obese";
            }
            else if (BMI1 > 31.5 && BMI1 <= 32.5)
            {
                Obese32.Begin();
                Description.Text = "Obese";
            }
            else if (BMI1 > 32.5 && BMI1 <= 33.5)
            {
                Obese33.Begin();
                Description.Text = "Obese";
            }
            else if (BMI1 > 33.5 && BMI1 <= 34.5)
            {
                Obese34.Begin();
                Description.Text = "Obese";
            }
            else if (BMI1 > 34.5 && BMI1 <= 35)
            {
                Obese35.Begin();
                Description.Text = "Obese";
            }
            else if (BMI1 > 35 && BMI1 <= 36.2)
            {
                cObese36.Begin();
                Description.Text = "Clinically obese";
            }
            else if (BMI1 > 36.2 && BMI1 <= 37.3)
            {
                cObese37.Begin();
                Description.Text = "Clinically obese";
            }
            else if (BMI1 > 37.3 && BMI1 <= 38.4)
            {
                cObese38.Begin();
                Description.Text = "Clinically obese";
            }
            else if (BMI1 > 38.4 && BMI1 <= 39.5)
            {
                cObese39.Begin();
                Description.Text = "Clinically obese";
            }
            else if (BMI1 > 39.5 && BMI1 <= 40)
            {
                cObese40.Begin();
                Description.Text = "Clinically obese";
            }
            else if (BMI1 > 40 && BMI1 <= 41.5)
            {
                mObese41.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 41.5 && BMI1 <= 42.5)
            {
                mObese42.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 42.5 && BMI1 <= 43.5)
            {
                mObese43.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 43.5 && BMI1 <= 44.5)
            {
                mObese44.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 44.5 && BMI1 <= 45.5)
            {
                mObese45.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 45.5 && BMI1 <= 46.5)
            {
                mObese46.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 46.5 && BMI1 <= 47.5)
            {
                mObese47.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 47.5 && BMI1 <= 48.5)
            {
                mObese48.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 > 48.5 && BMI1 <= 49.5)
            {
                mObese49.Begin();
                Description.Text = "Morbidly obese";
            }
            else if (BMI1 == 50)
            {
                mObese50.Begin();
                Description.Text = "Morbidly obese";
            }
            else
            {
                MessageBox.Show("Invalid weight or height.", "Information", MessageBoxButton.OK);
                BMI1 = 0;
            }

            Result.Text = (string.Format("{0}", BMI1));
        }