Why isn\'t continuing? and why isn\'t celsius working import javax.swing.JOption
ID: 665107 • Letter: W
Question
Why isn't continuing? and why isn't celsius working
import javax.swing.JOptionPane;
import java.util.Scanner;
public class lab_Exercise2_3
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double C = 0;
double F = 0;
String strDegrees=JOptionPane.showInputDialog("Enter 1 to convert Celsius tp Fahrenheit and 2 to convert Farhrenheit to Celsiu");
int degrees = Integer.parseInt(strDegrees);
switch(degrees)
{
case 1:
JOptionPane.showInputDialog("Enter the Celcius");
F= (9.0/5.0*(C+32));
JOptionPane.showMessageDialog(null,"The Fahrenheit is "+F);
break;
case 2:
JOptionPane.showInputDialog("Enter Fahrenheit");
C=(5.0/9*(F-32));
JOptionPane.showMessageDialog(null,"The Celcius is "+C);
String message= "Do you want to continue?";
String title = "Press yes to continue or no to stop";
int reply = JOptionPane.showConfirmDialog(null, message,title,JOptionPane.YES_NO_OPTION);
if (reply==JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
}
}
Explanation / Answer
import javax.swing.JOptionPane; public class CelciusToFahrenheit { public static void main(String[] arg){ String CelciusString = JOptionPane.showInputDialog("Enter the Celcius: "); Double Celcius = Double.parseDouble(CelciusString); Double Fahrenheit = (9.0 / 5) * Celcius + 32; String output = "Fahrenheit is " + Fahrenheit; JOptionPane.showMessageDialog(null,output); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.