In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy:
K E = 1 2 m υ 2
The variables in the formula are as follows: KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second.
Create a Java program with a function that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments. The function should return the amount of kinetic energy that the object has. Ask the user to enter values for mass and velocity, and then call the function you created to get the object’s kinetic energy.
sample output:
Enter mass in kilograms: 71
Enter velocity in meters per second: 5.5
The object's kinetic energy is: 1073.88 J.
import java.util.*;
public class App {
/**
* The start point of the program
*
* @param args
*
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter mass in kilograms: ");
double mass = keyBoard.nextDouble();
System.out.print("Enter velocity in meters per second: ");
double velocity = keyBoard.nextDouble();
double E = calculateE(mass, velocity);
System.out.printf("The object's kinetic energy is: 1073.88 J.\n\n", E);
keyBoard.close();
}
static double calculateE(double mass, double velocity) {
return (mass * velocity * velocity) / 2.0;
}
}
Comments
it's really work. Thank you so much ^^
Leave a comment