// Create a CalcEnergy application that prompts the user for the mass (in kg)
// and the velocity (in m/sec) and calculates the kinetic energy based on this
// formula: kinetic energy = (mass * (velocity squared)) / 2.
// Make the output appear meaningful and attractive (include proper units of
// measurement in the answer). (What is the unit of measurement for kinetic
// energy???)
import java.awt.*;
import hsa.Console;
public class CalcEnergy
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
double mass, velocity, kineticEnergy;
c.print ("Enter the object's mass (in kg): ");
mass = c.readDouble ();
c.print ("Enter the object's velocity (in m/sec): ");
velocity = c.readDouble ();
// now, calculate the object's kinetic energy
kineticEnergy = (mass * Math.pow (velocity, 2)) / 2;
c.print ("The object's kinetic energy is " + kineticEnergy);
c.println (" based on the its mass: " + mass + " kg");
c.println ("and its velocity: " + velocity + " m/sec");
} // main method
} // CalcEnergy class
No comments:
Post a Comment