java枚举多参数

java枚举多参数_第1张图片

package cn.gfurox.entity.enums.activity;

import java.math.BigDecimal;

public enum ActivityFormulaUtil {
	
	JOIN_PLAN_THREE("JOIN_PLAN",new BigDecimal(1000),3,40),
	JOIN_PLAN_SIX("JOIN_PLAN",new BigDecimal(1000),6,80),
	JOIN_PLAN_NINE("JOIN_PLAN",new BigDecimal(1000),9,120),
	JOIN_PLAN_TWELVE("JOIN_PLAN",new BigDecimal(1000),12,200),
	JOIN_PLAN_TWENTY_FOUR("JOIN_PLAN",new BigDecimal(1000),24,400),
	BUY_BID_THREE("BUY_BID",new BigDecimal(1000),3,28),
	BUY_BID_SIX("BUY_BID",new BigDecimal(1000),6,48),
	BUY_BID_NINE("BUY_BID",new BigDecimal(1000),9,68),
	BUY_BID_TWELVE("BUY_BID",new BigDecimal(1000),12,88),
	BUY_PLAN_TRANSFER("BUY_PLAN_TRANSFER",new BigDecimal(1000),0,12)
	;
	private String type;
	private BigDecimal amount;
	private int trem;
	private int rate;

	ActivityFormulaUtil(String type, BigDecimal amount,int trem,int rate) {
		this.type = type;
		this.amount = amount;
		this.trem = trem;
		this.rate = rate;
	}
	
	// 普通方法  传入type,trem,amount计算出相应的值
    public static BigDecimal getName(String type,int term, BigDecimal amount) {  
        for (ActivityFormulaUtil c : ActivityFormulaUtil.values()) {  
            if (c.getType().equals(type)&& c.getTrem() == term) {  
                return amount.divide(c.getAmount()).multiply(new BigDecimal(c.getRate())).setScale(0, BigDecimal.ROUND_HALF_UP);  
            }  
        }  
        return new BigDecimal(0); 
    }  
    public static void main(String[] args) {
    	System.out.println(getName("BUY_BID", 12, new BigDecimal(2100)));
    	System.out.println(ActivityFormulaUtil.BUY_BID_NINE);
	}
    
    
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public int getTrem() {
		return trem;
	}

	public void setTrem(int trem) {
		this.trem = trem;
	}

	public int getRate() {
		return rate;
	}

	public void setRate(int rate) {
		this.rate = rate;
	}

}

你可能感兴趣的:(Java基础)