用面向对象的思路进行程序编写。需在程序中,验证函数计算结果的正确性 超市,出售苹果和草莓 水果芒果

import java.math.BigDecimal;

public class ICBCTest {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }

    public static BigDecimal getShoppingAmountTotalPrice(String fruitType,Integer shoppingFruitItemAmount,Boolean isDisCount,Integer disCountCode){
        if(fruitType==null){
            return null;
        }
        if (fruitType.isEmpty()){
            return null;
        }
        if (shoppingFruitItemAmount==null){
            return null;
        }
        if (shoppingFruitItemAmount<0){
            return null;
        }
        if (isDisCount==null){
            return null;
        }
        if (disCountCode==null){
            return null;
        }
        BigDecimal totalAmount=new BigDecimal("0.00");
        if (!isDisCount){
            if (fruitType.equals(FruitName.APPLE)){
                BigDecimal multiply = FruitPrice.APPLE_PRICE.getPrice().multiply(new BigDecimal(shoppingFruitItemAmount));
                totalAmount.add(multiply);
                return totalAmount;
            } else if (fruitType.equals(FruitName.GLASS_DETAIL_FRUIT)) {
                BigDecimal multiply = FruitPrice.GLASS_DETAIL_FRUIT_PRICE.getPrice().multiply(new BigDecimal(shoppingFruitItemAmount));
                totalAmount.add(multiply);
                return totalAmount;
            }else if (fruitType.equals(FruitName.MANGO)){
                BigDecimal multiply = FruitPrice.MANGO_PRICE.getPrice().multiply(new BigDecimal(shoppingFruitItemAmount));
                totalAmount.add(multiply);
                return totalAmount;
            }
        }else {
            if (fruitType.equals(FruitName.GLASS_DETAIL_FRUIT)) {
                if(disCountCode.equals(DiscountEnum.DISCOUNT_ENUM_EIGHTY_PERCENT_GLASS_FRUIT.getDiscountCode())){
                    BigDecimal multiply = FruitPrice.GLASS_DETAIL_FRUIT_PRICE.getPrice().multiply(new BigDecimal(shoppingFruitItemAmount));
                    BigDecimal multiply1 = multiply.multiply(new BigDecimal("0.80"));
                    totalAmount.add(multiply1);
                    return totalAmount;
                }
            } else if (disCountCode.equals(DiscountEnum.DISCOUNT_ENUM_SHOPING_TOTAL_PRICE_MINUS.getDiscountCode())) {
                if (fruitType.equals(FruitName.APPLE)){
                    BigDecimal multiply = FruitPrice.APPLE_PRICE.getPrice().multiply(new BigDecimal(shoppingFruitItemAmount));
                    totalAmount.add(multiply);
                    return totalAmount;
                } else if (fruitType.equals(FruitName.MANGO)){
                    BigDecimal multiply = FruitPrice.MANGO_PRICE.getPrice().multiply(new BigDecimal(shoppingFruitItemAmount));
                    totalAmount.add(multiply);
                    if (totalAmount.equals(new BigDecimal("100.00"))){
                        totalAmount.subtract(new BigDecimal("10.00"));
                    }
                    return totalAmount;
                }
            }
        }
        return null;
    }
}
class SuperMarketCustomer{
    private String id;
    private String name;
    private String superMarketId;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSuperMarketId() {
        return superMarketId;
    }

    public void setSuperMarketId(String superMarketId) {
        this.superMarketId = superMarketId;
    }
}
class SuperMarket{
    private String id;
    private String name;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
class Goods{
    private String id;
    private String name;
    private BigDecimal price;
    private String superMarketId;
    private String discountActivityId;
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public String getSuperMarketId() {
        return superMarketId;
    }

    public void setSuperMarketId(String superMarketId) {
        this.superMarketId = superMarketId;
    }

    public String getDiscountActivityId() {
        return discountActivityId;
    }

    public void setDiscountActivityId(String discountActivityId) {
        this.discountActivityId = discountActivityId;
    }
}
class GoodsItem{
    private String id;
    private String name;
    private String goodsId;
    private Integer shoppingAmount;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public Integer getShoppingAmount() {
        return shoppingAmount;
    }

    public void setShoppingAmount(Integer shoppingAmount) {
        this.shoppingAmount = shoppingAmount;
    }
}
class DiscountActivity{
    private String id;
    private String name;
    private Integer discountCode;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getDiscountCode() {
        return discountCode;
    }

    public void setDiscountCode(Integer discountCode) {
        this.discountCode = discountCode;
    }
}
enum DiscountEnum{
    DISCOUNT_ENUM_EIGHTY_PERCENT_GLASS_FRUIT("0001","草莓水果价格打八折"),
    DISCOUNT_ENUM_SHOPING_TOTAL_PRICE_MINUS("0002","购物满100减10元");
    private String discountCode;
    private String desc;
    DiscountEnum(String discountCode,String desc){
        this.discountCode=discountCode;
        this.desc=desc;
    }

    public String getDiscountCode() {
        return discountCode;
    }

    public String getDesc() {
        return desc;
    }
}
enum FruitName{
    APPLE(0001,"苹果"),
    GLASS_DETAIL_FRUIT(0002,"草莓"),
    MANGO(0003,"芒果");
    private Integer fruidCode;
    private String descName;
    FruitName(Integer fruidCode,String descName){
        this.fruidCode=fruidCode;
        this.descName=descName;
    }

    public Integer getFruidCode() {
        return fruidCode;
    }

    public String getDescName() {
        return descName;
    }
}
enum FruitPrice{
    APPLE_PRICE(0001,"苹果8元一斤",new BigDecimal("8.00")),
    GLASS_DETAIL_FRUIT_PRICE(0002,"草莓13元一斤",new BigDecimal("13.00")),
    MANGO_PRICE(0003,"芒果20元一斤",new BigDecimal("20.00"));
    private Integer priceCode;
    private String priceDesc;
    private BigDecimal price;
    FruitPrice(Integer priceCode,String priceDesc,BigDecimal price){
        this.priceCode=priceCode;
        this.priceDesc=priceDesc;
        this.price=price;
    }

    public Integer getPriceCode() {
        return priceCode;
    }

    public String getPriceDesc() {
        return priceDesc;
    }

    public BigDecimal getPrice() {
        return price;
    }
}

#腾讯云智研发工作体验##总结:哪家公司面试体验感最好#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务