0

The score is increasing until 40 using the increaseScore() method.

If a boolean flag is true, the score will be reduced by 10 (so, in this case, it will be 30), and display score = 30 and grade = D in toString().

But I only can get score = 40 and grade = D in toString().

Is it possible to add return score; after score = score - 10; in findGrade()?

public int increaseScore(){
   score = score + 10;
   return score;
    }

public char findGrade(){
    if (flag)
        score = score - 10;

    char grade = 'A';

    if (80<=score)
        grade = 'A';
    else if (60<=score && score <= 79)
        grade = 'B';
    else if (40<=score && score <= 69)
        grade = 'C';
    else 
        grade ='D';

    return grade;
}

public String toString(){
    return teamName + " " + score + " " + findGrade();
}
Makoto
  • 104,088
  • 27
  • 192
  • 230
user5000
  • 37
  • 1
  • 6
  • 4
    Without getting into detail about what you are trying to do, simply put, a java method can only return a single item. (Note that you can return an array or something that in itself contains multiple items) – takendarkk Apr 29 '14 at 03:42
  • I'm not 100% clear on what you're trying to accomplish. `score` is declared as a field (well, I *hope* it is, since it's not declared anywhere else), so you don't really need to worry about returning multiple values from `findGrade()`. You already have access to the field, and you're using it in `toString()`. If you could provide more clarification as to why you think you need two return values, perhaps one of us could answer your question better? Perhaps it isn't a raw duplicate of returning two things from a function? – Makoto Apr 29 '14 at 03:52
  • if you want to return more than one value, Put them in an Array and return the array – upog Apr 29 '14 at 04:26
  • 1
    I've started up a meta discussion on this post; [you can find it here.](http://meta.stackoverflow.com/q/252653/1079354) I believe that it's actually an XY problem; there's a better way to solve this issue as opposed to returning two values. – Makoto Apr 29 '14 at 05:09
  • You need to make sure that `findGrade` gets called before `toString` uses `score`. Perhaps `public String toString(){ char grade = findGrade(); return teamName + " " + score + " " + grade; }` – Ben Voigt Dec 31 '14 at 01:58

1 Answers1

1

you can add another method for toString() use:

public String findGradeString() {
    return score + ":" + findGrade();
}
public String toString(){
    return teamName + " " + score + " " + findGradeString();
}
Farvardin
  • 5,336
  • 5
  • 33
  • 54