Advertisement
Guest User

code

a guest
Nov 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. public static double[] surfGrav(double[] plntGrav) //Find Gravity of Each Planet
  2. {
  3. Scanner inFile = new Scanner(new File("surfaceGravity.txt")); //Opens file from PlanetGravity
  4.  
  5. //Empty Variables
  6. int index = 0;
  7.  
  8. while(inFile.hasNext()) //Finds gravity of planets from PlanetGravity program
  9. {
  10. plntGrav[index] = inFile.nextDouble(); //ROOT OF PROBLEM i think.
  11. index++;
  12. }
  13. inFile.close();
  14. return plntGrav;
  15. }
  16.  
  17. public static double[] plntWeight(double[] weights) //Find Mass & Weight
  18. {
  19. //Input
  20. Scanner in = new Scanner(System.in);
  21. System.out.println("Please enter your weight in pounds.");
  22. double userWeight = in.nextDouble();
  23.  
  24. //Empty Variables
  25. int index = 0;
  26.  
  27. //Finds surfaceGrav
  28. double[] gravity = surfGrav();
  29.  
  30. double userMass = (surfGrav(plntGrav[2]) * 453.59237); //Converts input from pounds to grams to find mass
  31. for(double gravit : gravity) //Finds user's weight on each individual planet
  32. {
  33. weights[index] = (userMass * gravit);
  34. index++;
  35. }
  36. return weights;
  37. }
  38.  
  39. public static void main(String[] args) //Output info
  40. {
  41. String[] planets = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"};
  42.  
  43. //Finds weight
  44. double[] weight = plntWeight(weights);
  45.  
  46. System.out.printf("%25s%n", "Planetary Data");
  47. System.out.println();
  48. System.out.printf("%8s%20f%18f%n", "Planet", "Gravity", "Weight (lbs)");
  49. System.out.println("============================================================================");
  50. for(int index = 0; index < planets.length; index++)
  51. {
  52. System.out.printf("%8s%20f%18f%n", planets[index], gravity[index], weight[index]);
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement