import java.util.*;
import java.text.*;
import javax.swing.*;
class Lab4{
public static void main (String[] args) {;
String tempF;
double num, F;
JFrame myWindow=new JFrame();
mywindow.setSize(300,300);
mywindow.setTitle("Calculator");
mywindow.setVisible(true);
mywindow.setLocation(400, 100);
tempF=JOptionPane.showInputDialog(myWindow, "Enter temp...");
F=125;
num=((5.0/9.0)*(F-32));
JOptionPane.showMessageDialog(myWindow, "The temp is "+num);
}
}
Currently I'm taking basic programming class in College "Object Oriented Programming" using JGrasp. My teacher want us to create a program where it will ask the user to enter current temperature in Fahrenheit and then convert it to degrees Celsius using the formula C=5/9*(F-32). However I need to display the converted temperature using a dialog box. I got to this part and I'm totally confused as to what to do next or for that matter what I'm doing wrong. My problem is how can I define the variable F so you can put any number in and it would convert it into degrees Celsius. I tried "Scanner scanner=new Scanner(System.in);" and then "F=scanner.nextDouble();" and that didn't work. I believe I have to use the parseDouble() method or parseInt() method or simply converting string to Int but I have no clue therefore I just need help to what exactly am I doing wrong thank you for helping.

New Topic/Question
Reply



MultiQuote





|