Write a simple Java application which calculates the cutoff frequency in a simpl
ID: 3551102 • Letter: W
Question
Write a simple Java application which calculates the cutoff frequency in a simple RC circuit. Your application should ask the user to enter the capacitor and resistor values of the circuit. You must use the JOptionPane class to collect the user's input. The capacitor and resistor values should be treated as floating point values. Calculate the cutoff frequency in hertz: freq = 1 / (2 * pi * capacitor (in farads) * resistor (in ohms)). You must use the JOptionPane class to output the result. Your output must show two digits after the decimal point and contain explanatory text. Make sure you remember to import what your program will use.
Explanation / Answer
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class FunctionTest {
public static void main(String args[]){
String rval = " ";
String cval = " ";
int age = 0;
rval = JOptionPane.showInputDialog(null, "Enter the value of C: ");
float c = Float.parseFloat(rval);
cval = JOptionPane.showInputDialog(null, " Enter the value of R: ");
float r = Float.parseFloat(cval);
DecimalFormat df = new DecimalFormat("#.##");
float x = (float) (1.0 / (2 * 3.14 * c * r));
JOptionPane.showConfirmDialog(null, df.format(x), "The cut off frequency is ", JOptionPane.OK_CANCEL_OPTION);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.