One form of Ohm’s law is:
E = I×R
where,
- E is applied voltage and is measured in volts(V)
- I is circuit current and is measured in amperes(A)
- R is circuit resistance and is measured in ohms(Ω)
To find E when I = 5mA and R = 2.7KΩ, first convert 5mA to 5×10-3A, 2.7KΩ to 2.7×103Ω and then perform the following calculation
E = 5×10-3A × 2.7×103Ω = 13.5V.
Create Java program that (a) creates a supporting class name, Ohm, which contains one method named, getOhm, that takes two inputs, I (circuit current) and R (circuit resistance), to return the calculation result of E= I×R, (b) create a class with “main” method in it, (c) the main method takes two double values, I and R, (d) create instance of the Ohm class and use it to call the getOhm method with the two double values (I and R) passing to the getOhm method, (e) display returned calculated value in a message box. Be sure to use ampere (A) and ohm (Ω) as units.
import javax.swing.JOptionPane;
class Ohm{
/**
* The method named, getOhm, that takes two inputs, I (circuit current) and R (circuit resistance),
* to return the calculation result of E= I×R,
* @param totalTorpedos
* @param torpedosFired
*/
public double getOhm(double I,double R){
return I*R;
}
}
public class Q183110 {
/***
* Main method
* @param args
*/
public static void main(String[] args) {
double I=Double.parseDouble(JOptionPane.showInputDialog("Enter circuit current I(A): "));
double R=Double.parseDouble(JOptionPane.showInputDialog("Enter circuit resistance R(ohm): "));
Ohm ohm =new Ohm();
JOptionPane.showMessageDialog(null,ohm.getOhm(I, R)+" volts");
}
}
Example:
Comments
Leave a comment