Exemple #1
0
        private void CalculateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                RunningTime runningTime = new RunningTime();
                runningTime.Hours   = int.Parse(HoursText.Text);
                runningTime.Minutes = int.Parse(MinutesText.Text);
                runningTime.Seconds = int.Parse(SecondsText.Text);

                Pace pace = Calculation.CalculateAveragePace(double.Parse(DistanceTextKM.Text) + double.Parse(DistanceTextM.Text) / 1000, runningTime);

                string fixSeconds = "";
                if (pace.Seconds < 10)
                {
                    fixSeconds = "0";
                }

                if (double.Parse(DistanceTextKM.Text) + double.Parse(DistanceTextM.Text) / 1000 == 0)
                {
                    MessageBox.Show("Incorrect Data!");
                }
                else
                {
                    PaceText.Content = pace.Minutes + ":" + pace.Seconds + fixSeconds + " min/km";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Incorrect Data!");
            }
        }
Exemple #2
0
        public static Pace CalculateAveragePace(double Distance, RunningTime runningTime)
        {
            Pace pace = new Pace();

            double timeInSeconds = (runningTime.Hours * 3600) + (runningTime.Minutes * 60) + runningTime.Seconds;

            double paceSeconds = timeInSeconds / Distance;

            pace.Minutes = (int)paceSeconds / 60;
            pace.Seconds = (int)paceSeconds % 60;

            return(pace);
        }