欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

java_支付方式有Cash(现金)、WeChatPay(微信)、Alipay(支付宝)、BankCard(银行卡)、CreditCard(信用卡)五种,建立一个枚举类Pay包含这五种支付方式。类Pa

程序员文章站 2022-03-10 09:01:42
package sevenone;public interface Message {public void show();}enum Pay implements Message {Cash(“现金”, 1000.0) {@Overridepublic void show() {System.out.println(“现金支付1000.0”);}},WeChatPay(“微信”, 6666.6) {@Overridepublic void show() {System.out....

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