# Falling Distance

Page 1 of 1

## 4 Replies - 23164 Views - Last Post: 28 October 2009 - 04:55 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=135102&amp;s=ebe2cce51e569dfa90a396d14b4af224&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 harjot00

Reputation: 1
• Posts: 33
• Joined: 15-October 09

# Falling Distance

Posted 28 October 2009 - 04:18 PM

Question:

Quote

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.

Write a method named falling Distance that accepts an object's falling time (in seconds) as an argument. The method should return the distance, in meters, that the object has fallen during that time interval. Demonstrate the method by calling it in a loop that passes the value 1 through 10 as arguments, and displays the return value.

heres what I have so far, I don't really understand the point of the loop am I on the right track here?
```import java.util.Scanner;
public class Chapter5Question5
{
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();
fallingDistance(fallingTime);
}
public static void fallingDistance(double fallingTime)
{
double a=0.5, g=9.8;//0.5=1/2
double d=(a*g)*(fallingTime*fallingTime);
for(int x=1; x<11; x++)
{
System.out.println("");
}
}
}

```

Is This A Good Question/Topic? 0

## Replies To: Falling Distance

### #2 japanir

• jaVanir

Reputation: 1014
• Posts: 3,025
• Joined: 20-August 09

## Re: Falling Distance

Posted 28 October 2009 - 04:27 PM

also it says that you should call your method 10 times.

```public static double fallingDistance(double fallingTime){
//make calculations into your double d variable.
//and return its value using "return"
return d;
}

```

then, inside the main method, from what i understand from the instructions, you should pass the xffrom 1 to 10 to the fallinDistance method.
so dont scan a value to fallingTime. instead use:
```for(int x=1;x<11;x++){
System.out.println(fallingDistance(x));
}

```

this should do.

### #3 harjot00

Reputation: 1
• Posts: 33
• Joined: 15-October 09

## Re: Falling Distance

Posted 28 October 2009 - 04:33 PM

japanir, on 28 Oct, 2009 - 03:27 PM, said:

also it says that you should call your method 10 times.

```public static double fallingDistance(double fallingTime){
//make calculations into your double d variable.
//and return its value using "return"
return d;
}

```

then, inside the main method, from what i understand from the instructions, you should pass the xffrom 1 to 10 to the fallinDistance method.
so dont scan a value to fallingTime. instead use:
```for(int x=1;x<11;x++){
System.out.println(fallingDistance(x));
}

```

this should do.

Thank you for the reply so I tried what you are saying:
```import java.util.Scanner;
public class Chapter5Question5
{
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();
fallingDistance(fallingTime);

for(int x=1;x<11;x++)
{
System.out.println(fallingDistance(x));
}

}
public static void fallingDistance(double fallingTime)
{
double a=0.5, g=9.8;//0.5=1/2
double d=(a*g)*(fallingTime*fallingTime);
return (d);
}
}

```

but I get an error for the system.out.println in the loop:
void type not allowed here why is this?

### #4 harjot00

Reputation: 1
• Posts: 33
• Joined: 15-October 09

## Re: Falling Distance

Posted 28 October 2009 - 04:53 PM

OK so I just figured out what I was doing wrog, and now it seems to work, The loop part was really confusing me, I still don't understand this question fully (mainly why the loop has to be there) but it seems to work fine thank you for your help
```import java.util.Scanner;
public class Chapter5Question5
{
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);
}
}

```

### #5 japanir

• jaVanir

Reputation: 1014
• Posts: 3,025
• Joined: 20-August 09

## Re: Falling Distance

Posted 28 October 2009 - 04:55 PM

you left it as void.
you should change your method to return double as i suggested.
```public static double fallingDistance(double fallingTime){
//code
}

```

you see the double i wrote instead of the void?
that indicates that the method returns a double value.