mercredi 24 novembre 2021

Working on a Letter Grade for Numeric Grade Program. How can I update double values when certain if conditions are met? [duplicate]

This is my program below. Essentially, I want to have double initialgradeStep and double finalgradeOut update when those if conditions are met. How can I do this with my current program?

public static void main(String[] args) {
    Scanner lettGradein = new Scanner(System.in);

    System.out.println("Enter a letter grade: ");
    String lettGrade = lettGradein.nextLine();

    double initialgradeStep = 0;
    double finalgradeOut = 0;

    if (lettGrade == "A") {
        initialgradeStep = 4.0;
    } else if (lettGrade == "B") {
        initialgradeStep = 3.0;
    } else if (lettGrade == "C") {
        initialgradeStep = 2.0;
    } else if (lettGrade == "D") {
        initialgradeStep = 1.0;
    } else if (lettGrade == "F") {
        initialgradeStep = 0;
    } else if (lettGrade.substring(0, 1) == "+") {
        finalgradeOut = initialgradeStep + 0.3;
    } else if (lettGrade.substring(0, 1) == "-") {
        finalgradeOut = initialgradeStep - 0.3;
    }
}

Aucun commentaire:

Enregistrer un commentaire