Ask Question
19 February, 18:54

Scientists measure an object's mass in kilograms and its weight in newtons. If you knowthe amount of mass of an object in kilograms, you can calculate its weight in newtons withthe following formula: weight 5 mass 3 9.8

Write a program that asks the user to enter an object's mass, and then calculates its weight. If the object weighs more than 500 newtons, display a message indicating that it is tooheavy. If the object weighs less than 100 newtons, display a message indicating that it istoo light

+1
Answers (1)
  1. 19 February, 21:44
    0
    public class WeightCalculator {

    private static DecimalFormat df2 = new DecimalFormat ("#.##");

    public static void main (String args[]) {

    //create scanner to receive user input

    Scanner in = new Scanner (System. in);

    //alert user to input mass

    System. out. println ("Enter the Mass in Kg");

    //collect the input as a string

    String s = in. nextLine ();

    //convert string to double and multiply by 9.8

    Double weight = Double. valueOf (s) * 9.8;

    //Print out answer formatted to 2 decimal place

    System. out. println ("The Weight is " + df2. format (weight) + "N");

    //conditional statement to check if weight is less than 100

    if (weight < 100) {

    System. out. println ("Oops, it is too light");

    }

    //conditional statement to check if weight is more than 500

    if (weight > 500) {

    System. out. println ("Oops, it is too heavy");

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Scientists measure an object's mass in kilograms and its weight in newtons. If you knowthe amount of mass of an object in kilograms, you ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers