主要功能实现:输入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