Java program?
In order for an object to escape planet's gravitational pull, it must attain a minimum initial velocity called the escape velocity. The escape velocity varies from planet to planet.Create a Java program which calculates the escape velocity for the planet. Your program should first prompt the user for the circumference of the planet and then the acceleration due to gravity on the planet. From this information you determine the radius, mass, and escape velocity of the planet using the following equations:
vescape = square root(2 *G*m/r); g = G m/r^2; G = 6.67x10-11 Nm^2/kg^2.
The console output should look similar to:
Circumference of planet, km? 38000
Acceleration due to gravity, m/s2? 9.8
Calculating the escape velocity?
Planet radius: 6047.9 km
Planet mass: 5372.0 x 10^21 kg
Escape velocity: 10.9 km/s;
***********************This is my code so far******************
import java.util.Scanner;
class EscapeVelocity
{
public static void main( String[] args)
{
double circum;
double accel;
System.out.print("What is the circumference of the planet in km? ");
Scanner scanner= new Scanner(System.in);
circum = scanner.nextDouble();
System.out.print("What is the acceleration due to gravity in m/s^2? ");
scanner= new Scanner(System.in);
accel = scanner.nextDouble();
System.out.println();
System.out.println("Calculating the escape velocity...");
final double PI = 3.14159;// constant value declared
double radius = circum/(2*PI);
System.out.println("Planet Radius: "+ radius+" km");
final double G= 0.0000000000667 ;
double mass = accel*Math.pow(radius,2)/G;
System.out.println("Planet mass: "+ mass+ " kg");
double vescape= Math.sqrt(2*G*mass/radius);
System.out.println("Escape Velocity: "+ vescape+ " km/s");
}
}
Please suggest modifications to get the exact ans. as in the question.
I also think the last double vescape formula is getting me the wrong ans. so please help
View Answers
February 26, 2010 at 1:41 AM
February 26, 2010 at 7:31 AM
thank you very much javaquest
Related Tutorials/Questions & Answers:
Advertisements