Last active
October 2, 2015 17:28
-
-
Save HiroNakamura/2285042 to your computer and use it in GitHub Desktop.
Uso básico de Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JOptionPane; | |
import java.util.List; | |
import java.util.ArrayList; | |
enum Genero{ | |
HOMBRE, MUJER; | |
} | |
/* | |
@author yo | |
compilar: javac -g Prog19.java | |
ejecutar: java Prog19 HOMBRE MUJER MUJER PERRO HOMBRE MUJER MUJER | |
salida: | |
entradas: HOMBRE | |
entradas: MUJER | |
entradas: MUJER | |
entradas: PERRO | |
entradas: HOMBRE | |
entradas: MUJER | |
entradas: MUJER | |
Hombre: 2 | |
Mujer: 4 | |
*/ | |
public class Prog19{ | |
private Genero genero; | |
public Prog19(Genero genero){ | |
this.genero=genero; | |
} | |
public static void main(String ... args)throws Exception{ | |
Prog19 p;//new Prog19[args.length]; | |
Prog19 q; | |
int c1=0,c2=0; | |
String[] vector=new String[args.length]; | |
if(args.length!=0){ | |
for(int i=0;i<args.length;i++){ | |
vector[i]=args[i]; | |
System.out.println("entradas : "+vector[i]); | |
} | |
for(String e: vector){ | |
if(e.equals("HOMBRE")){ | |
p=new Prog19(Genero.HOMBRE); | |
c1++; | |
}else if(e.equals("MUJER")){ | |
q=new Prog19(Genero.MUJER); | |
c2++; | |
}else{ | |
JOptionPane.showMessageDialog(null,"no existe ese genero"); | |
} | |
} | |
System.out.println("Hombre: "+c1); | |
System.out.println("Mujeres: "+c2); | |
}else{ | |
JOptionPane.showMessageDialog(null,"no hay nada que escribir"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment