// Create a CurrentElectricity2 application that prompts the user for the
// following values: electrical charge flowing (in Coulombs --> represented
// by 'q') and time (in seconds) and then uses these values to calculate the
// electrical current (in Amperes) based on this formula:
// electrical current = electrical charge / time.
// Make the output appear meaningful and attractive (include proper units of
// measurement in the answer).
import java.awt.*;
import hsa.Console;
public class CurrentElectricity2
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
double q, time, electrCurrent;
c.println ("Enter the value for electrical charge flowing ");
c.print ("(in Coulombs --> represented by 'q'): ");
q = c.readDouble ();
c.print ("Enter the value for time (in seconds): ");
time = c.readDouble ();
c.println ();
if (time > 0)
{
// now, calculate the electrical current (in Amperes)
electrCurrent = q / time;
c.println ("The electrical current is " + electrCurrent + " Ampere(s),");
c.println ("based on the electrical charge flowing: ");
c.println (q + " Coulombs, and the time elapsed: " + time
+ " seconds");
}
else
{
c.println ("The time entered: " + time + " must be a positive ");
c.println (" value in order to perform division");
}
} // main method
} // CurrentElectricity2 class
No comments:
Post a Comment