The gravitational force F between two bodies of masses m1 an
The gravitational force F between two bodies of masses m1 and m2 is given by the equation F = Gm1m2/r2 where G is the gravitational constant (6.674×105// Nm0/kg0), m1 and m2 are the masses of the bodies in kilograms, and r is the distance between the centers of mass of the two bodies. Write a function to calculate the gravitational force between two bodies given their masses and the distance between them. Test your function by determining the force on a 1200 kg satellite in orbit 49,000 km above the center of mass of the Earth (the mass of the Earth is 5.972× 100= kg). You must include a proper comment header block and you must use good programming practices
Solution
/**
* This application calculates gravitation force
* The gravitational force F between two bodies of masses m1 and m2 is given by the equation
* F = Gm1m2/r2 where G is the gravitational constant (6.674×105// Nm0/kg0),
* m1 and m2 are the masses of the bodies in kilograms,
* and r is the distance between the centers of mass of the two bodies.
*/
public class GravitationForceCalculator {
public static final double G = 667400.0;
public static final double MASS_OF_EARTH = 5.972 * Math.pow(10, 24);
/**
* Test function
* @param args
*/
public static void main(String args[])
{
final double massOfSatellite = 1200;
final double distance = 49000;
System.out.println(\"Gravitational force: \" + calculateGravitationalForce(MASS_OF_EARTH, massOfSatellite, distance) + \" N\");
}
public static double calculateGravitationalForce(double m1, double m2, double r)
{
return G*m1*m2/Math.pow(r, 2);
}
}

