package com.logic.annotation;
/**
* @author logic
* @version 1.0
*/
/*
创建一个Color枚举类
有 RED,BLUE,BLACK,YELLOW,GREEN这个五个枚举值/对象;
Color有三个属性redValue,greenValue,blueValue,
创建构造方法,参数包括这三个属性,
每个枚举值都要给这三个属性赋值,三个属性对应的值分别是
red:255,0,0 blue:0,0,255 black:0,0,0 yellow:255,255,0 green:0,255,0
要求Color实现该接口 定义接口,里面有方法show,
show方法中显示三属性的值
将枚举对象在switch语句中匹配使用
*/
public enum Color implements A {
RED(255, 0, 0), BLUE(0, 0, 255),
BLACK(0, 0, 0), YELLOW(255, 255, 0),
GREEN(0, 255, 0);
private int redValue;
private int greenValue;
private int blueValue;
Color(int redValue, int greenValue, int blueValue) {
this.redValue = redValue;
this.blueValue = blueValue;
this.greenValue = greenValue;
}
@Override
public void show() {
System.out.println(redValue + "," + blueValue + "," + greenValue);
}
}
interface A {
void show();
}
package com.logic.annotation;
/**
* @author logic
* @version 1.0
*/
public class Homework08 {
public static void main(String[] args) {
Color black = Color.BLACK;
black.show();
switch (black) {
case RED:
System.out.println("匹配到红色");
break;
case BLUE:
System.out.println("匹配到蓝色");
break;
case BLACK:
System.out.println("匹配到黑色");
break;
case GREEN:
System.out.println("匹配到绿色");
break;
case YELLOW:
System.out.println("匹配到黄色");
}
}
}