You sure can and the result would be the same. Looking at it from a process perspective there's one extra step doing it that way rather than returning early. However there is an even more elegant solution that I used that may not be evident for first time java students. If you get rid of the if statement altogether and just put: return isBonus() ? sum * 3 : sum;
Thank you!
for question 1, can you just put "sum = sum * 3;" inside the if statement for bonus and then return it at the end?
You sure can and the result would be the same. Looking at it from a process perspective there's one extra step doing it that way rather than returning early.
However there is an even more elegant solution that I used that may not be evident for first time java students. If you get rid of the if statement altogether and just put:
return isBonus() ? sum * 3 : sum;