I AM USING VISUAL BASIC, USING THE PROGRAMMING LANGUAGE OF C# When an object is
ID: 3680978 • Letter: I
Question
I AM USING VISUAL BASIC, USING THE PROGRAMMING LANGUAGE OF C#
When an object is falling becuase of gravity, the following formula can be used to determine the distance the object falls in a specific time period:
d = 1/2 * g * t2
The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time in seconds that the object has been falling. Create an application that allows the user to enter the amount of time that an object has fallen and then displays the distance that the object fell. The application should have a function named "FallingDistance." The "FallingDistance" function should accept an object's falling time (in seconds) as an argument. The function should return the distance in meters that the object has fallen during that time interval.
*this requires a return argument
Explanation / Answer
When an object is falling because of gravity, the following formula can be used to determine the distance of the object falls in a specific time period.
d = 1/2 gt2
The Variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, that the object has been falling.
Java
public class Falling
{
public static void main (String [] args)
{
double fallingTime;
Scanner keyboard=new Scanner(System.in);
System.out.println("Ener the falling time (in seconds): ");
fallingTime=keyboard.nextDouble();
for(int x=1;x<11;x++)
{
System.out.println(fallingDistance(x));
}
public static double fallingDistance(double fallingTime)
{
double a=0.5, g=9.8;//0.5=1/2
double d=(a*g)*(fallingTime*fallingTime);
return (d);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
C# Falling Distance
If you start a new Windows Forms project and add a textbox for entering the time, a label for showing the distance fallen and a button to calculate the distance, then the code needed will be as follows:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const double g = 9.8;
private void btnCalculate_Click(object sender, EventArgs e)
{
double time;
double.TryParse(txtTime.Text, out time);
double distance = 0.5 * g * time * time;
lblDistance.Text = distance.ToString();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.