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();
}
scoreis 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 fromfindGrade(). You already have access to the field, and you're using it intoString(). 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?findGradegets called beforetoStringusesscore. Perhapspublic String toString(){ char grade = findGrade(); return teamName + " " + score + " " + grade; }