// Create a UniformMotion (with constant acceleration) application that prompts
// the user for a value for: intial velocity (in m/sec), time (in seconds), and
// acceleration (in metres / (second squared)) and calculates the distance (in metres)
// based on this formula: (initial velocity * time) + (1/2 * acceleration)
// * time squared.
// Make the output appear meaningful and attractive (include proper units of
// measurement in the answer).
import java.awt.*;
import hsa.Console;
public class UniformMotion
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
double time, initialVelocity, acceleration, distance;
c.print ("Enter the time elapsed (in seconds): ");
time = c.readDouble ();
c.print ("Enter the initial velocity (in m/sec): ");
initialVelocity = c.readDouble ();
c.print ("Enter the acceleration rate (in m/(sec squared)"): ");
acceleration = c.readDouble ();
// now, calculate distance travelled (in metres)
distance = (initialVelocity * time) + (1 / 2 * acceleration) * Math.pow (time, 2);
c.println ("The distance travelled is " + distance + " m based on the ");
c.println ("time: " + time + " seconds, the initial velocity: " + initialVelocity);
c.println ("and the acceleration rate: " + acceleration);
} // main method
} // UniformMotion class
No comments:
Post a Comment