1
I created a Class enum
of java
public enum Cor {
AZUL(1),VERMELHO(2),VERDE(3);
private int var;
Cor(int var)
{
this.var = var;
}
}
In the main
I’ll create a menu using do/while
and switch/case
and will be shown the colors, how to pick the chosen color and pass in a method parameter?
On the menu it goes like this
System.err.println("Escolha uma cor");
System.err.println("1-Azul");
System.err.println("2-Vermelho");
System.err.println("3-Verde");
The user type 1 must catch the color Blue.
You want the value of
var
? Example:Cor minhaCor = Cor.AZUL;
and thenint valorCor = minhaCor.val
, something like this you want? If yes, just create a getter within the Enum:public int getVar() { return this.var; } .... minhaCor.getVar()
– AlfredBaudisch
@Alfredbaudisch take a look at the edition
– Vale