【解決方法】Javaでそのコードのプロセスを変更するのに問題があります


コードの変更に問題があります。 ブール値でそれを行いたいのですが、その方法がわかりません。 それは私を混乱させるだけです。

これは私の仕事です:

タイヤ圧試験

すべてのタイヤの空気圧が 35 ~ 45 の間であるかどうかを確認します。タイヤがこの範囲外の場合は、すぐに警告メッセージが発行されます。 その後、プログラムは値の読み取りと処理を続けます。

警告メッセージが発生した場合、プログラムは最後に最終警告メッセージを発行します。 この目的のために、ブール変数 pressureOK を宣言します。

ブール圧力OK

true で初期化し、タイヤが有効な範囲外にある場合は値を false に設定します。

彼らはブール値のタスクで私を助けてくれますが、私は無知で混乱しているので、それを行う方法がわかりません。 正直なところ、私は文字通りすべてを試しました。 解決策を求める前に、可能な限りのことを常に試します。なぜなら、試しずに解決策を求めるだけでは役に立たないからです。

私のコード:

import java.util.Scanner;

public class Tyrepressure {

    public static void main(String[] args) {

        Scanner scanner1 = new Scanner(System.in);

        System.out.println("Enter your tyrepressure of your right-front-tyre in pounds per square inch: ");
        double rightFrontTyre = scanner1.nextDouble();

        System.out.println(" "); // For space in between the user input

        System.out.println("Enter your tyrepressure of your left-front-tyre in pounds per square inch: ");
        double leftFrontTyre = scanner1.nextDouble();

        System.out.println(" "); // For space in between the user input

        System.out.println("Enter your tyrepressure of your left-back-tyre in pounds per square inch: ");
        double rightBackTyre = scanner1.nextDouble();

        System.out.println(" "); // For space in between the user input

        System.out.println("Enter your tyrepressure of your right-back-tyre in pounds per square inch: ");
        double leftBackTyre = scanner1.nextDouble();

        System.out.println(" "); // For space in between the user input

        if (rightFrontTyre >= 35 && rightFrontTyre <= 45) {
            System.out.println("right-front-tyre = " + rightFrontTyre + " psi, your tyrepressure is okay!");
        } else {
            System.out.println("right-front-tyre = " + rightFrontTyre
                    + " psi, your tyrepressure is critical, it is out of the allowed range!");
        }

        System.out.println(" "); // For space in between the user input

        if (leftFrontTyre >= 35 && leftFrontTyre <= 45) {
            System.out.println("left-front-tyre = " + leftFrontTyre + " psi, your tyrepressure is okay!");
        } else {
            System.out.println("left-front-tyre = " + leftFrontTyre
                    + " psi, your tyrepressure is critical, it is out of the allowed range!");
        }

        System.out.println(" "); // For space in between the user input

        if (rightBackTyre >= 35 && rightBackTyre <= 45) {
            System.out.println("right-back-tyre = " + rightBackTyre + " psi, your tyrepressure is okay!");
        } else {
            System.out.println("right-back-tyre = " + rightBackTyre
                    + " psi, your tyrepressure is critical, it is out of the allowed range!");
        }

        System.out.println(" "); // For space in between the user input

        if (leftBackTyre >= 35 && leftBackTyre <= 45) {
            System.out.println("left-back-tyre = " + leftBackTyre + " psi, your tyrepressure is okay!");
        } else {
            System.out.println("left-back-tyre = " + leftBackTyre
                    + " psi, your tyrepressure is critical, it is out of the allowed range!");
        }

        System.out.println(" "); // For space in between the user input

        if (rightFrontTyre < 35 || rightFrontTyre > 45 || leftFrontTyre < 35 || leftFrontTyre > 45
                || rightBackTyre < 35 || rightBackTyre > 45 || leftBackTyre < 35 || leftBackTyre > 45) {
            System.out.println("You have to check your tyrepressure!");
        }
    }
}

出力:

Enter your tyrepressure of your right-front-tyre in pounds per square inch: 
40
 
Enter your tyrepressure of your left-front-tyre in pounds per square inch: 
32
 
Enter your tyrepressure of your left-back-tyre in pounds per square inch: 
11
 
Enter your tyrepressure of your right-back-tyre in pounds per square inch: 
40
 
right-front-tyre = 40.0 psi, your tyrepressure is okay!
 
left-front-tyre = 32.0 psi, your tyrepressure is critical, it is out of the allowed range!
 
right-back-tyre = 11.0 psi, your tyrepressure is critical, it is out of the allowed range!
 
left-back-tyre = 40.0 psi, your tyrepressure is okay!
 
You have to check your tyrepressure!

それは正常に動作しますが、最後の部分をブール型のデータ型で行う必要があり、すでに述べたように、方法がわかりません…..

私が試したこと:

質問の冒頭に記載しました。

コメント

タイトルとURLをコピーしました