-3
public class Lampada {
private boolean ligada = true;
/*
* Métodos acessores e modificadores
*/
public void setLigada(boolean alteraEstado) {
this.ligada = alteraEstado;
}
public boolean isLigada() {
return ligada;
}
}
====
It doesn’t work, I did it this other way
public class Main {
public static void main (String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Comando 'ligar' ou 'desligar' lampada.");
String comando = sc.nextLine();
Lampada lampada = new Lampada();
switch (comando) {
case "ligar":
lampada.setLigada(true);
System.out.println("Lampada ligada.");
break;
case "desligar":
lampada.setLigada(false);
System.out.println("Lampada desligada.");
break;
}
}
}
Where are you running the files? (for example, in an IDE or command prompt) and in the new version, you modified the class
Lampada
?– NinjaTroll
Maybe you forgot to recompile the files, I tested the code and it worked
– NinjaTroll
I used the class
Lampada
that @Maniero suggested and the classMain
of its edition– NinjaTroll
One of the possibilities is that Java is somehow getting confused when performing operations, try to delete the files from
Lampada
and ofMain
and try again– NinjaTroll