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

Respuesta :

Answer:

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");

       }            

   }

}

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE