I'm trying to write down something more sophisticated than simple Fahrenheit to Celsius and vice versa converter. I'm trying to use JoptionPane for better fell but I'm stuck in one place and have no idea how to resolve this (line 32 and 37 - method not applicable for the arguments ()) any help will be appreciated.
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class ex74v3 {
public static void main(String[] args) {
temp();
new ex74v3();
}
public ex74v3() {
boolean done=false;
while(!done){
done=true;
String[] ans=new String[11];
String[] choice={
"(°F) to (°C)",
"(°C) to (°F)",
};
int choice_indx=JOptionPane.showOptionDialog(null, "Choose type of conversion", "Choice",
0,JOptionPane.QUESTION_MESSAGE ,
null,choice,0);
ans[0]=choice[choice_indx];
if(choice_indx==1 || choice_indx==2) {
done=false;
}else{
choice_indx=JOptionPane.showMessageDialog(null, "Fahrenheit to Celsius: " + baseFtC() + " (°C)");
}
if(choice_indx==2) {
done=false;
}else{
choice_indx=JOptionPane.showMessageDialog(null, "Celsius to Fahrenheit : " + baseCtF() + " (°F)");
}
}
}
public static int temp() {
String value = JOptionPane.showInputDialog(null, "Enter value ");
@SuppressWarnings("unused")
int log;
return log = Integer.parseInt(value);
}
public int baseCtF(int value) {
int conversion = (int) (temp() * 1.8 + 32);
return conversion;
}
public int baseFtC(int value) {
int conversion = (int) ((temp() - 32) / 1.8);
return conversion;
}
}
Ok, there is an other way, easier, thanks anyway ;]
import java.text.DecimalFormat;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class ex74v4 {
public static void main(String[] a) {
DecimalFormat digit = new DecimalFormat("0.00");
String value = JOptionPane.showInputDialog(null, "Enter value ");
float log;
log = Float.parseFloat(value);
JFrame frame = new JFrame();
Object stringArray[] = { "Celsius to Fahrenheit", "Fahrenheit to Celsius" };
int reply = JOptionPane.showOptionDialog(frame, "Choose conversion type of value: " + digit.format(log), "MiniConverter",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, stringArray,
stringArray[0]);
if (reply == JOptionPane.YES_OPTION) {
DecimalFormat digit2 = new DecimalFormat("0.00");
double conversion = log * 1.8 + 32;
JOptionPane.showMessageDialog(frame, log + " " + "(°C) equals " + digit2.format(conversion) + " (°F)", "MiniConverter", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
else {
DecimalFormat digit3 = new DecimalFormat("0.00");
double conversion = (log - 32) / 1.8;
JOptionPane.showMessageDialog(frame, log + " " + "(°F) equals " + digit3.format(conversion) + " (°C)", "MiniConverter", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
}