2015-10-26 71 views
0

我想写一些比简单的华氏温度更复杂的摄氏温度和反之亦然转换器。我试图使用JoptionPane更好的下降,但我卡在一个地方,不知道如何解决这个问题(第32和37行 - 方法不适用于参数())任何帮助将不胜感激。摄氏度,华氏转换器在java与JOptionPane

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; 
    } 
} 

回答

0

好了,有一个其他的方式,更容易,还是要谢谢你]

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); 
    } 

} 

}