samedi 7 novembre 2020

Else-If command creating a variable after executing their own ifs

I know the title's confusing but hear me out.

I wanted to create a Scanner-type program that will asks the user to type their grade, while showing their remarks using both switch and else-if.

I tried to make the Else-If command to find the kind of grade the user have and make a variable that will work/recognized by the switch command. It just doesn't seems to work.

System.out.print("Enter FullGrade: ");
int FullGrade = ExpectedGradePeko.nextInt();
    
    if(FullGrade < 0)
    { String Expec = "AAA"; }
    else if(FullGrade < 79)
    { String Expec = "BBB"; }
    else if(FullGrade < 84)
    { String Expec = "CCC"; }
    else if(FullGrade < 89)
    { String Expec = "DDD"; }
    else if(FullGrade < 100)
    { String Expec = "EEE"; }
    
    
switch(Expec)
{
    case "AAA":
        System.out.println("Did not meet expectations");
        break;
    case "BBB":
        System.out.println("Fairly Satisfactory");
        break;
    case "CCC":
        System.out.println("Satisfactory");
        break;
    case "DDD":
        System.out.println("Very Satisfactory");
        break;
    case "EEE":
        System.out.println("Outstanding");
        break;
    }

Aucun commentaire:

Enregistrer un commentaire