Advertisement
Guest User

Untitled

a guest
Jan 26th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.text.DecimalFormat;
  3. /**
  4. * This program will calculate the weight of an object on every planet
  5. * in our solar system, Pluto, and Earth's moon.
  6. *
  7. * @author Anon
  8. * @version 1/26/2019
  9. * This work complies with the *INSERT UNIVERSITY* honor code.
  10. */
  11.  
  12. public class PlanetWeights {
  13. /**
  14. * Main method.
  15. * @param args - command line arguments.
  16. */
  17. public static void main(String[] args) {
  18. // Inputs
  19. Scanner in = new Scanner(System.in); // Scanner f0r user input.
  20. System.out.print("Enter the name of the item: "); // User prompt.
  21. String item = in.nextLine(); // User's item name.
  22. System.out.print("How much does the item weigh? "); // User prompt.
  23. double weight = in.nextDouble(); // User's item weight.
  24. in.nextLine(); // Fixes scanner bug.
  25. System.out.print("What is the unit of measure? "); // User prompt.
  26. String measure = in.nextLine(); // User's preferred unit.
  27.  
  28. // Format for output: the 0s are replaced if decimals are needed.
  29. DecimalFormat commas = new DecimalFormat("###,##0.000");
  30.  
  31. // Output.
  32. System.out.printf("\n"
  33. + "On Mercury, the " + item + " weighs about "
  34. + "%s " + measure + ".\n"
  35. + "On Venus, the " + item + " weighs about "
  36. + "%s " + measure + ".\n"
  37. + "On the Moon, the " + item + " weighs about "
  38. + "%s " + measure + ".\n"
  39. + "On Mars, the " + item + " weighs about "
  40. + "%s " + measure + ".\n"
  41. + "On Jupiter, the " + item + " weighs about "
  42. + "%s " + measure + ".\n"
  43. + "On Saturn, the " + item + " weighs about "
  44. + "%s " + measure + ".\n"
  45. + "On Uranus, the " + item + " weighs about "
  46. + "%s " + measure + ".\n"
  47. + "On Neptune, the " + item + " weighs about "
  48. + "%s " + measure + ".\n"
  49. + "On Pluto, the " + item + " weighs about "
  50. + "%s " + measure + ".\n",
  51. commas.format(weight * 0.378),
  52. commas.format(weight * 0.907),
  53. commas.format(weight * 0.166),
  54. commas.format(weight * 0.377),
  55. commas.format(weight * 2.364),
  56. commas.format(weight * 1.064),
  57. commas.format(weight * 0.889),
  58. commas.format(weight * 1.125),
  59. commas.format(weight * 0.067));
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement