2014-08-31 87 views
-3

我应该做一个程序,将华氏温度转换成摄氏温度和华氏温度。我也应该使用输入类方法提示输入,我的程序应该有多种方法。到目前为止,这是我想出来的:华氏度到摄氏度使用多种方法

public class FahrenheitoCelsius 

{ 

    public static double conversion_fahrenheit_to_celsius() 
     { 
      if((F >= 0) | (F< 0)) 
      { 
      System.out.println(" The temperature is (Celsius_to_Fahrenheit(y)) degrees. "); 
      } 
      else 
      { 
      System.out.println(" The temperature is (Fahrenheit_to_Celsius(x)) degrees. "); 

      } 
     } 




    public static double Fahrenheit_degrees(double F) 
     { 
     double F = 32; 
     } 
    public static void Celsius_degrees(double C) 
    { 
     double C = 0; 
    } 


    public static double Fahrenheit_to_Celsius(double x) 
    { 
     x = 5/9 * ((Fahrenheit_degrees(F)) - 32); 
    } 
    public static double Celsius_to_Fahrenheit(double y) 
     { 
     y = (9/5 * (Celsius_degrees(C))) + 32; 
     } 

} 

我也应该使用以下一些:

import javax.swing.*; 


public class Input 
{ 
    public static byte getByte(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return Byte.parseByte(input); 
    } 

    public static short getShort(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return Short.parseShort(input); 
    } 

    public static int getInt(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return Integer.parseInt(input); 
    } 

    public static long getLong(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return Long.parseLong(input); 
    } 

    public static float getFloat(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return Float.parseFloat(input); 
    } 

    public static double getDouble(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return Double.parseDouble(input); 
    } 

    public static boolean getBoolean(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return Boolean.parseBoolean(input); 
    } 

    public static char getChar(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return input.charAt(0); 
    } 

    public static String getString(String s) 
    { 
     String input = JOptionPane.showInputDialog(s); 
     return input; 
    } 

} 

如何整合这些到我的程序? 注意:我不确定到目前为止我的程序是否正确;任何反馈将不胜感激,因为我是新来的Java。

+0

你需要学习编码java,这就是你的代码有什么问题。 – Gumbo 2014-08-31 21:57:35

回答

0

你的程序有几个错误的东西,但是你需要自己找到并修复它们。我可是会向您提供一个起点:

public static void main(String[] args) { 
    String choice = Input.getString("Do you want to convert from Fahrenheit to Celsius (type 'F') or from Celsius to Fahrenheit (type 'C')"); 
    if ("c".equalsIgnoreCase(choice)){ 
     //celsius --> fahrenheit code 
    } else { 
     //fahrenheit --> celsius code 
    } 
} 
1

我注意到的第一件事是在转换类方法“conversion_fahrenheit_to_celsius”是不正确的。它总能让你回想起你在印刷线上所拥有的那些字符串。你也需要输入你的方法,导致你使用的方法需要输入(温度)。

所以正确的方法是:

public static double conversion_fahrenheit_to_celsius(double y, double x) 
     { 
      if((F >= 0) | (F< 0)) 
      { 
      System.out.println(" The temperature is " + Celsius_to_Fahrenheit(y) + " degrees. "); 
      } 
      else 
      { 
      System.out.println(" The temperature is " + Fahrenheit_to_Celsius(x) " degrees. "); 

      } 
     } 

你需要使用的输入类的主要方法,如用户ljgw显示。

我建议你看一些教程,然后你看看如何编写Java。一个选择是TheNewBoston - Java(初学者)编程教程https://www.youtube.com/playlist?list=PLFE2CE09D83EE3E28