java_支付方式有Cash(现金)、WeChatPay(微信)、Alipay(支付宝)、BankCard(银行卡)、CreditCard(信用卡)五种,建立一个枚举类Pay包含这五种支付方式。类Pa
package sevenone;
public interface Message {
public void show();
}
enum Pay implements Message {
Cash(“现金”, 1000.0) {
@Override
public void show() {
System.out.println(“现金支付1000.0”);
}
},
WeChatPay(“微信”, 6666.6) {
@Override
public void show() {
System.out.println(“微信支付支付6666.6”);
}
},
Alipay(“支付宝”, 19999.9) {
@Override
public void show() {
System.out.println(“支付宝支付19999.9”);
}
},
BankCard(“银行卡支付”, 10000.0) {
@Override
public void show() {
System.out.println(“银行卡支付10000.0”);
}
},
CreditCard(“信用卡支付”, 8888.8) {
@Override
public void show() {
System.out.println(“信用卡支付8888.8”);
}
};
private final String type;
private double mount;
private Pay(String type, double mount) {
this.type = type;
this.mount = mount;
}
}
package sevenone;
public class Demo {
public static void main(String[] args) {
Pay cash =Pay.valueOf(“Cash”);
cash.show();
Pay alipay =Pay.valueOf(“Alipay”);
alipay.show();
Pay wechatpay =Pay.valueOf(“WeChatPay”);
wechatpay.show();
Pay bankcard =Pay.valueOf(“BankCard”);
bankcard.show();
Pay creditcard =Pay.valueOf(“CreditCard”);
creditcard.show();
}
}
本文地址:https://blog.csdn.net/m0_52723455/article/details/109850037
上一篇: 爬楼梯