健康私人定制网站怎么做,上海兼职做网站,教育类门户网站,vs2008 做网站题目要求
创建一个Color枚举类有RED,BLUE,BLACK,YELLOW,GREEN这五个枚举值/对象Color有三个属性redValue#xff0c;greenValue#xff0c;blueValue创建构造方法#xff0c;参数包括这三个属性每个枚举值都要给这三个属性赋值#xff0c;三个属性对应的值分别是red#…题目要求
创建一个Color枚举类有RED,BLUE,BLACK,YELLOW,GREEN这五个枚举值/对象Color有三个属性redValuegreenValueblueValue创建构造方法参数包括这三个属性每个枚举值都要给这三个属性赋值三个属性对应的值分别是red25500 blue00255 black000 yellow2552550 green02550定义接口里面有方法show要求Color实现该接口show方法中显示三属性的值将枚举对象在switch语句中匹配使用 package com.shedu.homework;public class Homework08 {public static void main(String[] args) {Color[] colors Color.values();for (Color color: colors){System.out.print(color);color.show();}}
}//1.创建一个Color枚举类
enum Color implements ShowValue{
//2.有RED,BLUE,BLACK,YELLOW,GREEN这五个枚举值/对象
//6.red25500 blue00255 black000 yellow2552550 green02550RED(255,0,0),BLUE(0,0,255),BLACK(0,0,0),YELLOW(255,255,0),GREEN(0,255,0);
//3.Color有三个属性redValuegreenValueblueValueprivate int renValue;private int greenValue;private int blueValue;//4.创建构造方法参数包括这三个属性private Color(int renValue, int greenValue, int blueValue) {this.renValue renValue;this.greenValue greenValue;this.blueValue blueValue;}public int getRenValue() {return renValue;}public int getGreenValue() {return greenValue;}public int getBlueValue() {return blueValue;}Overridepublic void show() {System.out.println(属性为renValue,greenValue,blueValue);}}interface ShowValue{public void show();
}