2016-11-17 7 views
-2

私はネットBeanとJavaを初めて使用し、ネットBean GUIを使用してリニア変換テーブルを作成する必要があります。これらは選択肢です:インチからセンチメートルまで
フィートからセンチメーター
ヤードからメーター
マイルからキロメートル。次の式は、メートル単位に測定の英語インペリアル単位を変換するために使用することができます。Netbeans/Javaでのパラメータ受け渡しの使用

Centimeters = Inches * 2.54  
Centimeters = Feet * 30  
Meters = Yards * 0.91  
Kilometers = Miles * 1.6 

それはパラメータ渡しを使用して作成する必要があり、これは私が持っているものである

call.`バックメソッドに値を返す必要がありますこれまでに完了しました:

int conversion;  
double centimetres = 0,value, metres = 0, kilometres = 0;  
conversion=Integer.parseInt(conversioninput.getText());  
value=Integer.parseInt(valueinput.getText());  
if (conversion==1)  
    centimetres=value*2.54;  
    output.setText(""+value+" inches = "+centimetres+ " centimetres"); 
if (conversion==2)  
    centimetres=value*30;  
    output.setText(""+value+" feet = "+centimetres+ " centimetres");  
if (conversion==3)  
    metres=value*0.91;  
    output.setText(""+value+" yards = "+metres+ " metres");  
if (conversion==4)  
    kilometres=value*1.6;  
    output.setText(""+value+" miles = "+kilometres+ " kilometres"); 

パラメータの受け渡しを含める必要がありますが、その方法はわかりません。私はオンラインコースをやっているし、それは何も説明していない

+0

何パラメータあなたは合格しようとしていますか?どこからどこまで? – bradimus

+0

私は最後に 'return'を使うことができるようにパラメータを渡そうとしており、if文をどこに含めるのか使いたいと思っています。ご協力ありがとうございます –

答えて

1

何をしたいと思うことは、このようなものである:あなたの主なメソッドの内部でそれを呼び出すためにその後

public float conversion(int value, int conversion) { 
    // put your code inside this method 
} 

だけで実行します。

conversion(40, 2); 

あなたは一般的にプログラミングに慣れていないようですが、conversion変数の場合はenumsです。そして、セットアップは、のようなクラスの何か:

public enum Conversion { 
    InchToCentimeter, 
    FeetToCentimeter, 
    YardsToMeters, 
    KilometersToMiles 
} 

はここで列挙型のための良い出発点です:https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

+0

ありがとうございますuser123 –

関連する問題