2 Comments
User's avatar
Abelardo's avatar

I claim to my students they don't use magical numbers even with the switch statements:

```java

switch(aVariable) {

case A_CONSTANT: ...

// more cases

}

```

Expand full comment
Abelardo's avatar

The body of the setVolume method can be simplified with this one-line expression:

return Math.max(MIN_VOLUME, Math.min(level, MAX_VOLUME));

Nevertheless, sometimes it is preferable to write several lines (by including if , else if and else as you did) when the inline expression becomes a bit confused.

This is an opinionated refactoring.

Nice post! Thanks again, @JavinPaul and Soma!

Expand full comment