java用(HashMap,ArrayList)模拟购物车

主要功能实现:输入1 查看全部商品库商品
                       输入2 添加商品到购物车中
                       输入3 删除购物车中物品 

                       输入4 修改购物车中商品数量
                        输入5对购物车中物品结账
                        输入6 退出购物系统

1.封装商品库类:

public class Product {
    private Integer productid;
    private String productname;
    private String category;
    private float price;
    public Integer getProductid() {
        return productid;
    }
    public void setProductid(Integer productid) {
        this.productid = productid;
    }
    public String getProductname() {
        return productname;
    }
    public void setProductname(String productname) {
        this.productname = productname;
    }
    public String getCategory() {
        return category;
    }
    public void setCategory(String category) {
        this.category = category;
    }
    public float getPrice() {
        return price;
    }
    public void setPrice(float price) {
        this.price = price;
    }
    public Product() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Product(Integer productid, String productname, String category, float price) {
        super();
        this.productid = productid;
        this.productname = productname;
        this.category = category;
        this.price = price;
    }
    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return String.format("商品编号:%d\t商品名称:%s\t商品类型:%s\t商品价格%.2f\t", productid,productname,category,price);
    }
    
}
2.封装购物车类:值得注意的是购物车类中封装了商品

public class ShoppingCart {
    public

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值