Tuesday, 2 December 2014

// The "WorkAndPower1" class.

// Create a WorkAndPower application that prompts the user for the net force
// (in Newtons) and the distance travelled (in metres) and calculates the work
// required (in joules) based on this formula:  work = net force * distance.
// Make the output appear meaningful and attractive (include proper units of
// measurement in the answer).
import java.awt.*;
import hsa.Console;

public class WorkAndPower1
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
        c = new Console ();

        double work, distance, netForce;

        c.print ("Enter the net force exerted (in Newtons): ");
        netForce = c.readDouble ();

        c.print ("Enter the distance travelled (in metres): ");
        distance = c.readDouble ();

        // now, calculate the work required (in joules)
        work = netForce * distance;

        c.print ("The work required is " + work + " joules");
        c.println (" to exert a net force of ");
        c.print (netForce + " Newtons over a distance of ");
        c.println (distance + " metres");

    } // main method
} // WorkAndPower class

No comments:

Post a Comment