In: Computer Science
6) EscapeVelocity In order for an object to escape a planet's gravitational pull, it must attain a minimum initial velocity called the escape velocity. The escape velocity varies from planet to planet but it is the same for all objects on a given planet. Assume that we are analyzing the data that a small probe has collected while exploring some mystery planet. The probe has managed to obtain the circumference of the planet and the acceleration due to gravity at the surface. The probe must now determine what initial velocity it requires for takeoff in order to remove itself from the planet's gravitational force. You are to create a Java program that will determine this velocity. 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, your program should determine the radius, mass, and escape velocity of the planet using the following equations. In these equations, m kg is the planet's mass, r km is the planet's radius, G is the gravitational constant approximated by 6.6726 x 10-11m3 kg-1 s-2 , and a m/s2 is the acceleration due to gravity on the surface of the planet. Your program should read input and print output as shown in the following example. (The values shown after the question marks are supplied by the user.) Circumference (km) of planet? 38000 Acceleration due to gravity (m/s^2) on planet? 9.8
As you didn't tell me how to Format output but I did my best in formatting the answer and if you need further assistance do comment, I'll be happy to help you.
Code
import java.util.*;
import java.lang.Math;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Welcome to the Escape Velocity Application\n");
System.out.println("To begin, please enter the following information below\n");
System.out.println("Circumference (km) of planet? ");
double circum = input.nextDouble();
System.out.println("Acceleration due to gravity (m/s^2) on planet? ");
double acc = input.nextDouble();
//Gravitational constant
double G = 6.67408e-11;
//Radius
circum = circum*Math.pow(10, 3); // convert km to m
double r =circum/(2*Math.PI);
//Mass
double m = acc*(Math.pow(r, 2)/G);
//Escape Velocity
double e = (Math.sqrt((2.0*G*(m))/r));
e = e*Math.pow(10,-3);//converting escape velocity to km/s from m/s
r = r*Math.pow(10,-3);//converting radius to km from m
System.out.println("\nCalculating the escape velocity ...");
System.out.println("\nPlanet radius : "+r+" km");
System.out.println("\nPlanet mass : "+m+" kg.");
System.out.println("\nEscape velocity : "+e+" km/s.");
}
}