Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.text.DecimalFormat;
- /**
- * This program will calculate the weight of an object on every planet
- * in our solar system, Pluto, and Earth's moon.
- *
- * @author Anon
- * @version 1/26/2019
- * This work complies with the *INSERT UNIVERSITY* honor code.
- */
- public class PlanetWeights {
- /**
- * Main method.
- * @param args - command line arguments.
- */
- public static void main(String[] args) {
- // Inputs
- Scanner in = new Scanner(System.in); // Scanner f0r user input.
- System.out.print("Enter the name of the item: "); // User prompt.
- String item = in.nextLine(); // User's item name.
- System.out.print("How much does the item weigh? "); // User prompt.
- double weight = in.nextDouble(); // User's item weight.
- in.nextLine(); // Fixes scanner bug.
- System.out.print("What is the unit of measure? "); // User prompt.
- String measure = in.nextLine(); // User's preferred unit.
- // Format for output: the 0s are replaced if decimals are needed.
- DecimalFormat commas = new DecimalFormat("###,##0.000");
- // Output.
- System.out.printf("\n"
- + "On Mercury, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On Venus, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On the Moon, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On Mars, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On Jupiter, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On Saturn, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On Uranus, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On Neptune, the " + item + " weighs about "
- + "%s " + measure + ".\n"
- + "On Pluto, the " + item + " weighs about "
- + "%s " + measure + ".\n",
- commas.format(weight * 0.378),
- commas.format(weight * 0.907),
- commas.format(weight * 0.166),
- commas.format(weight * 0.377),
- commas.format(weight * 2.364),
- commas.format(weight * 1.064),
- commas.format(weight * 0.889),
- commas.format(weight * 1.125),
- commas.format(weight * 0.067));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement