The class looks ready, but an improvement can be made in the estaApagada()
method:
boolean estaApagada() {
return !aceso;
}
This will return the opposite of the variable on, which is exactly the status expected by the method.
There are other things that can be improved, such as the fact that you do not set a more restricted visibility to the% change% with%. Now if it needs two methods to be changed, it is not appropriate to leave it with a possible external access, adding aceso
you restrict the direct access to it.
Another detail cited by #
The class with the applied suggestions would look like this:
class Lampada {
private boolean aceso = true;
public void apaga() {
aceso = false;
}
public void acende() {
aceso = true;
}
public boolean estaAceso(){
return aceso;
}
}
Here are some links to the site that can help you learn more about basic java and object-oriented concepts:
What's the difference between public, default, protected, and private modifiers?
What are the concepts of cohesion and coupling?
Functional Programming and Object Oriented Programming. What are they and what are their main differences?