Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double[] surfGrav(double[] plntGrav) //Find Gravity of Each Planet
- {
- Scanner inFile = new Scanner(new File("surfaceGravity.txt")); //Opens file from PlanetGravity
- //Empty Variables
- int index = 0;
- while(inFile.hasNext()) //Finds gravity of planets from PlanetGravity program
- {
- plntGrav[index] = inFile.nextDouble(); //ROOT OF PROBLEM i think.
- index++;
- }
- inFile.close();
- return plntGrav;
- }
- public static double[] plntWeight(double[] weights) //Find Mass & Weight
- {
- //Input
- Scanner in = new Scanner(System.in);
- System.out.println("Please enter your weight in pounds.");
- double userWeight = in.nextDouble();
- //Empty Variables
- int index = 0;
- //Finds surfaceGrav
- double[] gravity = surfGrav();
- double userMass = (surfGrav(plntGrav[2]) * 453.59237); //Converts input from pounds to grams to find mass
- for(double gravit : gravity) //Finds user's weight on each individual planet
- {
- weights[index] = (userMass * gravit);
- index++;
- }
- return weights;
- }
- public static void main(String[] args) //Output info
- {
- String[] planets = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"};
- //Finds weight
- double[] weight = plntWeight(weights);
- System.out.printf("%25s%n", "Planetary Data");
- System.out.println();
- System.out.printf("%8s%20f%18f%n", "Planet", "Gravity", "Weight (lbs)");
- System.out.println("============================================================================");
- for(int index = 0; index < planets.length; index++)
- {
- System.out.printf("%8s%20f%18f%n", planets[index], gravity[index], weight[index]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement