枚举案例1

package meijuleixing;

public enum Color {
red,green,blue;
private Color(){
    
}

    
}
package meijuleixing;

public enum Style {
dimond("方块",1),flower(),heart("红心",3),peach("黑桃",4);

String name;
int value;

private Style(String name,int value){
    this.name=name;
    this.value=value;
}
public void sayHell(){
    System.out.println(this.name+"say hello");
}

public String toString(){
    return this.name+this.value;
}
private Style(){
    
}



}
package meijuleixing;

public class Puker {
int value;
Style style;
public Puker(int value, Style style) {
    super();
    this.value = value;
    this.style = style;
}

}
package meijuleixing;

public class TestColor {

    public static void main(String[] args) {
    Color c=Color.green;
    Color c1=Color.blue;
System.out.println(c.ordinal());    
System.out.println(c.name());    
Color[] cc=Color.values();
for(Color c2:cc){
    System.out.println(c2);
}
Puker p=new Puker(10,Style.flower);
Color c3=Color.valueOf("green");
System.out.println(c3.ordinal());

switch(c){
case green:
      System.out.println("小绿很精神");
      break;
case red:
    System.out.println("红色很热情");
    break;
default:
    System.out.println("小蓝很忧郁");
}

Color b=Color.green;
Color d=Color.valueOf("green");
System.out.println(b==d);

Style s=Style.dimond;
System.out.println(s);

Style ss=Style.flower;
System.out.println(ss);

    }

}

 

posted @ 2017-05-10 16:57  苏轼的红烧肉  阅读(154)  评论(0编辑  收藏  举报