Friday, March 21, 2014

Method_Ex_4 (Wk-8) Feb 24-28, 2014

Q: Write Method to compute Falling distance d = g * t2/2. (g is gravity, t is time in second, d is distance in feet). Get user input, call method, Display result.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Method_4
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("\nEnter time in second: ");
            double time = double.Parse(Console.ReadLine());

            double falldistance = FallingDistance(time);

            //Call DisplayResult
            //Convert distance to formatted string

            string fs = String.Format("Falling distance:0 {0} feet", falldistance);
            DisplayResult(fs);

            Console.ReadKey();
        }
        static double FallingDistance (double t)
        {
            double g = 32;
            double d = g * t * t / 2;
            return d;
        }
        static void DisplayResult(string s)
        {   //This method takes one input parameter to display.
            //It doesn't return anything. It means it returns a void.


            Console.WriteLine("\n=========================");
            Console.WriteLine(s);
            Console.WriteLine("\n=========================");
        }
    }
}

No comments:

Post a Comment