Tuesday, 2 December 2014

// The "CurrentElectricity4" class.

// Create a CurrentElectricity4 application that prompts the user for the
// following values: electrical voltage (in volts) and current (in Amperes) and
// then uses these values to calculate the electrical power (in Watts) based
// on this formula:  power = volts * current.
// Make the output appear meaningful and attractive (include proper units of
// measurement in the answer).

import java.awt.*;
import hsa.Console;

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

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

        double volts, current, power;

        c.print ("Enter the value for electrical voltage (in volts): ");
        volts = c.readDouble ();

        c.print ("Enter the value for electrical current (in Amperes): ");
        current = c.readDouble ();

        // now, calculate the electrical power produced (in Watts)
        power = volts * current;

        c.println ();

        c.println ("The amount of electrical power produced is " + power);
        c.println ("Watts, based on the electrical voltage: " + volts);
        c.println ("volts and the electrical current: " + current + " Amperes");

    } // main method
} // CurrentElectricity4 class

No comments:

Post a Comment