私はどこに問題があるのか知っています。なぜ私は問題があるのか分かります。私は単にそれを修正する方法を知りません。私の割り当てには6つ以上のメソッドがあり、そのうちの2つは入力を受け取り、2つはメソッドの入力を計算してループする必要があります。私はループがダウンしている、私はちょうど私が再び自分の番号を入力したいこの余分な線を持っている。どうしてか分かりません。私は自分のアウトプットを含めて、余分な行を取り除く必要がある場所と私のすべてのトラブルを引き起こしているような4つの方法を見てみることができます。Javaメソッド追加の入力行を作成する - それをどのように取り除きますか?
私の出力になりました:
デバッグ:融資ラウンドオブジェクトへ ようこそ電卓
このプログラムは、円 や球の体積の面積を計算します。
計算はユーザーの入力半径に基づいて行われます。
円の場合はC、球の場合はSを入力してください。 ありがとうございます。球の半径は何ですか(インチ単位):45.9
また、私の方法を修正する方法がわからないためです。 45.9
半径45.9インチの球の体積は405066.816立方インチです。
他のラウンドオブジェクト(Y/N)を計算しますか?Y 円の場合はC、球の場合はSを入力してください:C ありがとうございます。円の半径は何ですか(インチ単位):12.9
また、方法を修正する方法がわからないため、 12.9
半径12.9インチの円の面積は522.792インチです。
他のラウンドオブジェクト(Y/N)を計算しますか?n ラウンドオブジェクト計算機をご利用いただき、ありがとうございます。さようなら。 BUILD SUCCESSFUL(合計時間:34秒)。
私は私が私の方法を修正する方法を見つけ出すことができなかったので、私はノート「と別のものを追加して、この行を取り除きたい。ここ
である私全体のコード。もともと私は私の問題を引き起こしていた部品を置く。なぜ私はそれを行うためにそれを伝える方法を教えてください方法の私の最初の答えを保持し、次の方法にそれを押していないのですか?
package circlesphere;
//Scanner is in the java.until package
import java.util.Scanner;
public class CircleSphere {
static Scanner input = new Scanner(System.in);
//Step 1
public static void main(String[] args)
{
intro();
System.out.println();
do{
output();
} while (repeat());
}//end Main
/*
* A method definition consists of its method name, parameters,
* return value type, and body. The syntax for defining a method is as
* follows:
* modifier returnValueType methodName(list of parameters) {
* // Method body;
* }
*/
public static void intro()
{
// Display the welcome message
System.out.println("Welcome to the loan Round Object Calculator ");
//Blank Line
System.out.println();
System.out.println("This program will calculate the area of a circle ");
System.out.println(" or the volume of a sphere. ");
//Blank Line
System.out.println();
System.out.println("The calculations will be based on the user input radius. ");
}
//Step 2
public static String takeInput()
{
return input.nextLine();
}//end takeInput
//Step 2
public static double numberInput()
{
return input.nextDouble();
}//end numberInput
//Step 2
public static char alphaInput()
{
return input.next().charAt(0);
}//end alphaInput
//Step 6
public static boolean repeat()
{
char ask;
//Ask if user wants to repeat
System.out.print("Do you want to calculate another round object (Y/N): ");
ask = alphaInput();
if ((ask == 'N') || (ask == 'n'))
{
//Good bye comment
System.out.println("Thank you for using the Round Object Calculator. Goodbye. ");
return false;
}
else if ((ask == 'Y') || (ask == 'y'))
{
//Bug here. I have tried coping the if statement in main and that does
//not fix my problem. It won't accept calculateCS = printCircleSphere(shape);
//again and just spits me back to my bool.
return true;
}
return true;
}//end repeat
//Step 5
public static boolean output()
{
char calculateCS;
double radiusC, radiusS, areaCircle, volumeSphere;
//There seems to be a bug here when tryig to run through the bool loop.
calculateCS = printCircleSphere();
if ((calculateCS == 'C') || (calculateCS == 'c'))
{
double radiusCircle = 0;
System.out.print("Thank you. What is the radius of the circle (in inches): ");
radiusC = getRadius();
//Blank Line
System.out.println();
System.out.print("And Again, because I could not figure out how to fix my methods. ");
//There is a bug here and I don't know how to fix it because I need to call
//getRadius() in printCircleArea() to calculate radius. I don't know how to
//make getRadius just fill in the other methods once I enter it.
areaCircle = printCircleArea();
//Blank Line
System.out.println();
System.out.printf("The area of a circle with a radius of " + radiusC + "inches is %.3f inches. \n", areaCircle);
//Blank Line
System.out.println();
return true;
}
else if ((calculateCS == 'S') || (calculateCS == 's'))
{
System.out.print("Thank you. What is the radius of the sphere (in inches): ");
radiusS = getRadius();
//Blank Line
System.out.println();
System.out.print("And again, because I could not figure out how to fix my methods. ");
//There is a bug here and I don't know how to fix it because I need to call
//getRadius() in printShpereVolume() to calculate radius. I don't know how to
//make getRadius just fill in the other methods once I enter it.
volumeSphere = printSphereVolume();
//Blank Line
System.out.println();
System.out.printf("The volume of a sphere with a radius of " + radiusS + " inches is %.3f cubic inches. \n", volumeSphere);
//Blank Line
System.out.println();
return true;
}
else
return false;
}//end output
//Step 2 - Accept input for Circle or Sphere
public static char printCircleSphere()
{
//Prompt the user for C for circle or S for sphere.
System.out.print("Enter C for circle or S for sphere: ");
//Allows user to input the variable.
return alphaInput();
}//end printCircleSphere
//Step 2
public static double getRadius()
{
//Allows user to input the variable.
return numberInput();
}//end printRadiusS
public static final double PI = 3.141592653589793d;
//Step 3
public static double printCircleArea()
{
double circle = 0;
double radiusC = getRadius();//This is why I have a bug
radiusC = Math.pow(radiusC, 2) * PI;
return radiusC;
}//end printCircle
//Step 4
public static double printSphereVolume()
{
double sphere = 0;
double radiusS = getRadius();//This is why I have a bug
radiusS = 1.333333333 * PI * Math.pow(radiusS, 3);
return radiusS;
}//end printSphere
}//endclass
System.out.print(..)の代わりにSystem.out.println(..)を使用してください。)あなたのI/Oをより読みやすくするために... – lucasvw
出力に余分な行があるのを見るのは難しい –
'alphaInput()'メソッドのコードはどこですか? – lucasvw