Question: My assignment is : Write a Java program to calculate the gravitation attractive force between two bodies. Input the mass of the first body, the
My assignment is :
Write a Java program to calculate the gravitation attractive force between two bodies. Input the mass of the first body, the mass of the second body, and the distance between them. Calculate with a method using the formula: f = (Gm1m2) / d2 where G = 6.673 x 10-8
I think, I miss understand a method for void and return.
My code is,
import java.util.Scanner;
public class draft {
public static void main(String[] args) {
double mass1,mass2,distance, force;
Scanner scnr = new Scanner(System.in);
System.out.println("Enter the mass of first body: ");
mass1 = scnr.nextDouble();
System.out.println("Enter the mass of second body: ");
mass2 = scnr.nextDouble();
System.out.println("Enter the distance between two bodies: ");
distance = scnr.nextDouble();
}
public static double massMultiply (double mass1, double mass2){
double massMultiply = (mass1 * mass2);
return massMultiply;
}
public static double distanceSquare (double distance){
double distanceSquare = Math.pow(distance, 2);
return distanceSquare;
}
public static void double force (double massMultiple, double distanceSquare, double mass1, double mass2){
double force = 6.673e-8 * (massMultiple/distanceSquare);
System.out.println("Mass of first body: " + mass1);
System.out.println("Mass of second body: " + mass2);
System.out.println("Force: " + force);;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
