// Create an AvgVelocAndAccel application that prompts the user for the
// following values: initial velocity (v1)(in m/sec), final velocity (v2)
// (in m/sec), time (in seconds). It then calculates the average velocity and
// acceleration based on this formula: average = (v1 - v2) / time.
// Make the output appear meaningful and attractive (include proper units of
// measurement in the answer). The unit of measurement for acceleration is:
// metres / (sec squared).
import java.awt.*;
import hsa.Console;
public class AvgVelocAndAccel
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
double initialVelocity, finalVelocity, time;
double average;
c.print ("Enter the value for initial velocity (in m/sec): ");
initialVelocity = c.readDouble ();
c.println ("Enter the value for final velocity (in m/sec) ");
c.print (" (must be greater than the initial velocity value) (in m/sec): ");
finalVelocity = c.readDouble ();
c.print ("Enter the time elapsed (in seconds): ");
time = c.readDouble ();
if (time > 0)
{
// calculate average velocity and acceleration
// average velocity and acceleration
average = (finalVelocity - initialVelocity) / time;
c.println ("Your average velocity and acceleration is "
+ average + " m/(sec squared)");
}
else
{
c.println ("ERROR: You can only calculate the average velocity ");
c.println ("if the time elapsed is a positive value");
}
if (finalVelocity <= initialVelocity)
{
c.print ("ERROR: The final velocity: " + finalVelocity);
c.println (" must be greater than the initial velocity: ");
c.println (initialVelocity);
}
} // main method
} // AvgVelocAndAccel class
No comments:
Post a Comment