Acceleration of Gravity in Java

In summary: Multiplication and division have equal priority and are evaluated from left to right.It means that the parentheses around (distCenter * distCenter) are required.All other parentheses are redundant.
  • #1
obeying
8
0
Compute the acceleration of gravity for a given distance from the Earth's center, distCenter, assigning the result to accelGravity. The expression for the acceleration of gravity is: (G * M) / (d2), where G is the gravitational constant 6.673 x 10-11, M is the mass of the Earth 5.98 x 1024 (in kg) and d is the distance in meters from the Earth's center (stored in variable distCenter).

public class GravityCalculation {
public static void main (String [] args) {
double G = 6.673e-11;
double M = 5.98e24;
double accelGravity = 0.0;
double distCenter = 0.0;

distCenter = 6.38e6;

***Student code here***

System.out.println("accelGravity: " + accelGravity);
return;
}
}----------------------------------------------------------------------------------------------------------------------------------------

The answer has to compute to 9.803495445209855 however, I'm getting the answer 3.990454E14

This is how I inputted the code, did I format it wrong?


public class GravityCalculation {
public static void main (String [] args) {
double G = 6.673e-11;
double M = 5.98e24;
double accelGravity = 0.0;
double distCenter = 0.0;

distCenter = 6.38e6;

accelGravity = (G * M / distCenter * distCenter);

System.out.println("accelGravity: " + accelGravity);
return;
}
}
 
Technology news on Phys.org
  • #2
obeying said:
Compute the acceleration of gravity for a given distance from the Earth's center, distCenter, assigning the result to accelGravity. The expression for the acceleration of gravity is: (G * M) / (d2), where G is the gravitational constant 6.673 x 10-11, M is the mass of the Earth 5.98 x 1024 (in kg) and d is the distance in meters from the Earth's center (stored in variable distCenter).

public class GravityCalculation {
public static void main (String [] args) {
double G = 6.673e-11;
double M = 5.98e24;
double accelGravity = 0.0;
double distCenter = 0.0;

distCenter = 6.38e6;

***Student code here***

System.out.println("accelGravity: " + accelGravity);
return;
}
}----------------------------------------------------------------------------------------------------------------------------------------

The answer has to compute to 9.803495445209855 however, I'm getting the answer 3.990454E14

This is how I inputted the code, did I format it wrong?


public class GravityCalculation {
public static void main (String [] args) {
double G = 6.673e-11;
double M = 5.98e24;
double accelGravity = 0.0;
double distCenter = 0.0;

distCenter = 6.38e6;

accelGravity = (G * M / distCenter * distCenter);

System.out.println("accelGravity: " + accelGravity);
return;
}
}

Hi obeying! Welcome to MHB! ;)

If we read [M](G * M / distCenter * distCenter)[/M] from left to right, as equal priority operations are supposed to be applied, we get [M]((G * M / distCenter) * distCenter)[/M], which is actually equal to [M](G * M)[/M]...
 
  • #3
I like Serena said:
Hi obeying! Welcome to MHB! ;)

If we read [M](G * M / distCenter * distCenter)[/M] from left to right, as equal priority operations are supposed to be applied, we get [M]((G * M / distCenter) * distCenter)[/M], which is actually equal to [M](G * M)[/M]...

Okay, so I set it up wrong all together?
 
  • #4
obeying said:
Okay, so I set it up wrong all together?

We just need parentheses: [M]G * M / (distCenter * distCenter)[/M].
 
  • #5
I like Serena said:
We just need parentheses: [M]G * M / (distCenter * distCenter)[/M].

It worked! Thank you so much, I can't believe I was that close to getting it.
 

Attachments

  • Screen Shot 2016-08-13 at 3.53.07 PM.png
    Screen Shot 2016-08-13 at 3.53.07 PM.png
    46.4 KB · Views: 346
  • #6
obeying said:
Compute the acceleration of gravity for a given distance from the Earth's center, distCenter, assigning the result to accelGravity. The expression for the acceleration of gravity is: (G * M) / (d2), where G is the gravitational constant 6.673 x 10-11, M is the mass of the Earth 5.98 x 1024 (in kg) and d is the distance in meters from the Earth's center (stored in variable distCenter).

public class GravityCalculation {
public static void main (String [] args) {
double G = 6.673e-11;
double M = 5.98e24;
double accelGravity = 0.0;
double distCenter = 0.0;

distCenter = 6.38e6;

***Student code here***

System.out.println("accelGravity: " + accelGravity);
return;
}
}----------------------------------------------------------------------------------------------------------------------------------------

The answer has to compute to 9.803495445209855 however, I'm getting the answer 3.990454E14

This is how I inputted the code, did I format it wrong?


public class GravityCalculation {
public static void main (String [] args) {
double G = 6.673e-11;
double M = 5.98e24;
double accelGravity = 0.0;
double distCenter = 0.0;

distCenter = 6.38e6;

accelGravity = (G * M / distCenter * distCenter);

System.out.println("accelGravity: " + accelGravity);
return;
}
}

accelGravity = ((G * M) / (distCenter * distCenter))
 
  • #7
Does anyone know why the parenthesis matter this time ? When the program teaches that parentheis are not calculated but onnly used to keep things looking neat.
 
  • #8
Khbv said:
Does anyone know why the parenthesis matter this time ? When the program teaches that parentheis are not calculated but onnly used to keep things looking neat.
Multiplication and division have equal priority and are evaluated from left to right.
It means that the parentheses around (distCenter * distCenter) are required.
All other parentheses are redundant.
 

Related to Acceleration of Gravity in Java

1. What is the value of acceleration of gravity in Java?

The value of acceleration of gravity in Java is 9.8 meters per second squared (m/s²). This value is commonly used in simulations and calculations involving gravity in Java programming.

2. How can I calculate acceleration of gravity in Java?

Acceleration of gravity can be calculated using the formula: a = GM/r², where G is the gravitational constant (6.67 x 10^-11), M is the mass of the object, and r is the distance between the object and the center of gravity. In Java, this can be implemented using the Math.pow and Math.sqrt functions.

3. Can the acceleration of gravity be changed in Java?

No, the acceleration of gravity is a constant value in Java and cannot be changed. However, the value can be adjusted in simulations or calculations by using a different value for G or M.

4. How is acceleration of gravity represented in Java?

In Java, acceleration of gravity is typically represented using the variable "g" or "GRAVITY". It is also common to use the value 9.8 directly in calculations without assigning it to a variable.

5. How does the acceleration of gravity affect objects in Java programs?

The acceleration of gravity affects objects in Java programs by determining the rate at which they fall towards the ground. This value is used in simulations and games to create realistic gravity effects on objects such as projectiles, planets, and characters.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
830
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
3
Views
823
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
2
Views
12K
  • Programming and Computer Science
Replies
7
Views
2K
Back
Top