メソッドをその場で呼び出して、それらを目的の出力にリダイレクトするのに問題があります。
望ましい最終出力
重量変換
1.ポンドからキログラム
2.キログラムからポンドへ
変換したいタイプを選択してください: 1
ポンドを入力してください: 50
50ポンドは22.6796キログラムです。
(これは部分的なコードですが、誰かがこの問題を理解するのを手伝ってくれれば、残りを行うことができます)。
基本的に、「望ましい最終出力」ステートメントでは、「xx ポンドは xx.xxxx キログラムです。57 行目で最終的な計算を行うために他のメソッドを呼び出すのに問題があります。
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Declare variables
double nInitialPounds = 0;
double nInitialKilos = 0.0;
int nWeightSelection = 0;
double dInitialWeight = 0.0;
double dFinalWeight = 0.0;
double nPoundsToKilos = 0.0;
double nKilosToPounds = 0.0;
Scanner input = new Scanner (System.in);
//Display program title
System.out.println("WEIGHT CONVERSION");
//Display program option selections
System.out.println("1. Pounds to kilograms");
System.out.println("2. Kilograms to pounds");
//Print blank line to console
System.out.println("");
//Prompt user to make selection of desired output
System.out.println("Please select the type of conversion you would like to make: ");
//Read selection by user
nWeightSelection = input.nextInt();
//Begin while-loop statement
while (nWeightSelection == 1) {
//Prompt user to enter the amount of weight to be converted
System.out.print("Please enter the pounds: ");
// Read number entered by the user
dInitialWeight = input.nextDouble();
//Call weight conversion for Pounds to Kilos
nPoundsToKilos = poundsToKilos(nInitialKilos, dInitialWeight);
//Print final weight
System.out.println(+dInitialWeight + " pounds is " + nPoundsToKilos + " kilograms.");
break;
}
} //end Main method
/**
* This method converts weight in pounds to kilograms
* @param nPounds beginning weight in pounds
* @param nKilos desired output into kilograms
* @return nFinalWeight final weight in desired output
*/
public static double poundsToKilos(double nKilos, double nPounds) {
//Declare variables
double dFinalWeight = 0.0; //Final weight conversion from pounds to kilos
//Calculate weight conversion
dFinalWeight = (nPounds*2.204);
return dFinalWeight;
} //end method poundsToKilos
/**
* This method prints the converted weight to the console
* @param nPounds beginning weight in pounds
* @param nKilos desired output into kilograms
* @return nFinalWeight final weight in desired output
*/
public static double printWeight(double nKilos, double nPounds) {
//Declare variables
double dFinalWeight = 0.0; //Final weight conversion
return dFinalWeight;
} //end method printWeight