samedi 17 août 2019

How to fix my error in my IF-statement with a return type

I am trying to make a if statement that returns the mark grade depending on the score of the mark. It needs to return a type string which I thought I was doing when saying return "A" as the grade.

  public String markToGrade(int mark  
   {

    if (mark >=95) {
        return "A+";
    }
    else if (mark >=90) {
        return "A+";
    }
    else if (mark >=85) {
        return "A-";
    }
    else if (mark >=80) {
        return "B+";
    }
    else if (mark >=75) {
        return "B";
    }
    else if (mark >=70) {
        return "B-";
    }
    else if (mark >=60) {
        return "C+";
    }
    else if (mark >=50) {
        return "C";
    }
    else if (mark >=40) {
        return "C-";
    }
    else if (mark >=40) {
        return "D";
    }
    else {
        System.out.println("The assignment 1 score is " + assignment1 + "This is an invalid grade.");
    }

    // returns the grade (A,B,C) based on the mark given 
    //  EG: mark between 95 and 100 return "A+"
}

I expect when the user types in their mark the program will return the grade depending on the mark eg- 86 = A-

Aucun commentaire:

Enregistrer un commentaire