Tuesday, 2 December 2014

// The "CurrentElectricity1" class.

// Create a CurrentElectricity1 application that prompts the user for the
// following values: work done (in joules) and electrical charge (represented by q),
// and then uses these values to calculate the electrical potential difference (in volts)
// based on this formula:  volts = joules / q.
// Make the output appear meaningful and attractive (include proper units of
// measurement in the answer).
// The unit of measurement used for electrical charge is in Coulombs.
// (Assume that the quantity of Coulombs is anywhere from 1 to 100, with 1
// representing an extremely mild static charge, and 100 representing a bolt of
// lightning, an extremely severe electrical charge.)
import java.awt.*;
import hsa.Console;

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

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

        double work, q, volts;

        c.print ("Enter the value for work done (in joules): ");
        work = c.readDouble ();

        c.print ("Enter the value for electrical charge (in Coulombs) ");
        c.println ("anywhere from 1 (mild) to 100 (severe): ");
        q = c.readDouble ();

        // now, calculate the electrical potential difference (in volts)
        volts = work / q;

        c.println ("The electrical potential difference (in volts): " + volts);
        c.println (" is the work done: " + work + " joules divided by the ");
        c.print ("electrical charge (represented by 'q'): ");
        c.println (q + " Coulombs");

    } // main method
} // CurrentElectricity1 class

No comments:

Post a Comment