java 枚举一般用于,Java 将主体用于枚举常量

public class Main {/**来自 nowjava.com - 时代Java**/

public static void main(String[] args) {

for (Level s : Level.values()) {

String name = s.name();

String desc = s.toString();

int ordinal = s.ordinal();

int projectedTurnaroundDays = s.getValue();

double projectedCost = s.getProjectedCost();

System.out.println("name=" + name + ", description=" + desc

+ ", ordinal=" + ordinal + ", turnaround days="

+ projectedTurnaroundDays + ", projected cost=" + projectedCost);

}

}

}

enum Level {

LOW("Low Priority", 30) {

public double getProjectedCost() {

return 1000.0;

}

},

MEDIUM("Medium Priority", 15) {/*时 代 J a v a 公 众 号 - nowjava.com 提 供*/

public double getProjectedCost() {

return 2000.0;

}

},

HIGH("High Priority", 7) {

public double getProjectedCost() {

return 3000.0;

}

},

URGENT("Urgent Priority", 1) {

public double getProjectedCost() {

return 5000.0;

}

};

// Declare instance variables

private String description;

private int value;

// Declare a private constructor

private Level(String description, int a) {

this.description = description;

this.value = a;

}

// Declare a public method to get the turn around days

public int getValue() {

return value;

}

// Override the toString() method in the Enum class to return description

/**代码未完, 请加载全部代码(NowJava.com).**/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值