A method that returns an int can appear wherever a compatible int expression is needed. The Wildcats earn three league points for a win in this simplified model.
A method calculates the points, and a caller combines them with a bonus.
Read the example once before trying to explain every line. Then use the short explanations below to connect each part of the code with the soccer task.
public int GetWinPoints(int wins)
{
return wins * 3;
}
public int GetTrainingAward()
{
int bonus = 1;
int award = this.GetWinPoints(2) + bonus;
return award;
}Read the table one row at a time. Check when each value is observed: a value before a statement may differ from the value after that statement runs. Cover the result column and predict an answer before checking it.
| Wins argument | Method result | Bonus | Award |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 1 | 3 | 1 | 4 |
| 2 | 6 | 1 | 7 |
Use the diagram to follow the same soccer example in a different form. Start at the beginning and follow one execution at a time. Compare the labeled actions with the source code; do not assume every action in the picture runs.
Write your prediction and a short reason first. If you test the change, compare the observed values with that prediction. When they differ, find the first statement or decision where your explanation stops matching the code.