Ask Question
29 July, 21:57

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. 29 July, 22:31
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers