实现电商系统的商品库存管理

完成一个电商系统的商品库存管理,包含两个类:

  1. 商品类(编号,名称,类别,单价,库存量,生产地)
  2. 商品管理类
    要求在管理类中完成如下功能:
    a. 商品添加
    b. 查询指定价格范围的商品并显示
    c. 根据编号查询商品信息并显示
    d. 根据编号修改商品的单价和库存
    e. 显示所有商品信息
    f. 查询所有库存量低于指定数的商品信息

Goods类:

package com.softeem.work.goods;

public class Goods {
	int sno;
	String name;
	String type;
	int price;
	int store;
	String birthplace;

	public Goods(int sno, String name, String type, int price, int store, String birthplace) {
		super();
		this.sno = sno;
		this.name = name;
		this.type = type;
		this.price = price;
		this.store = store;
		this.birthplace = birthplace;
	}

	public int getSno() {
		return sno;
	}

	public void setSno(int sno) {
		this.sno = sno;
	}

	public String getName() {
		return name;
	}

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

	public String getType() {
		return type;
	}

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

	public int getPrice() {
		return price;
	}

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

	public int getStore() {
		return store;
	}

	public void setStore(int store) {
		this.store = store;
	}

	public String getBirthplace() {
		return birthplace;
	}

	public void setBirthplace(String birthplace) {
		this.birthplace = birthplace;
	}

	public void details() {
		System.out.println(sno + "\t" + name + "\t" + type + "\t" + price + "\t" + store + "\t" + birthplace + "\t");
	}

}

GoodManager类:

package com.softeem.work.goods;

public class GoodsManager {
	private Goods[] list;
	private int index;

	public GoodsManager() {
		list = new Goods[100];
	}

	public void findBySno1(int sno) {
		int i = findBySno(sno);
		Goods g = list[i];
		if (i == -1) {
			System.out.println("未找到该商品");
		} else {
			g.details();
		}
	}

	/**
	 * 根据编号显示某个商品的信息
	 */

	public int findBySno(int sno) {
		for (int i = 0; i < list.length; i++) {
			Goods g = list[i];
			if (g != null && g.getSno() == sno) {
				return i;
			}
		}
		return -1;
	}

	/**
	 * 添加某个商品的信息
	 */
	public void add(Goods g) {
		list[index++] = g;
	}

	/***
	 * 展示所有信息
	 */

	public void show() {
		for (int i = 0; i < list.length; i++) {
			Goods g = list[i];
			if (g != null) {
				g.details();
			}
		}
	}

	/**
	 * 根据指定价格的范围显示商品信息
	 * 
	 * @param price
	 */

	public void assignShow(int price) {
		for (int i = 0; i < list.length; i++) {
			Goods g = list[i];
			if (g != null && g.getPrice() >= price) {
				g.details();
			}
		}
	}

	/**
	 * 根据编号修改商品价格和库存量
	 * 
	 * @param sno
	 * @param price
	 * @param store
	 */
	public void change(int sno, int price, int store) {
		int i = findBySno(sno);
		if (i == -1) {
			System.out.println("未找到该商品");
		} else {

			list[i].setPrice(price);
			list[i].setStore(store);
		}
	}

	/**
	 * 查询库存量低于指定数商品的信息
	 * 
	 * @param store
	 */

	public void showLowStore(int store) {
		for (int i = 0; i < list.length; i++) {
			Goods g = list[i];
			if (g != null && g.store < store) {
				g.details();
			}
		}
	}

}

Test类:

package com.softeem.work.goods;

public class Test {

	public static void main(String[] args) {
		GoodsManager gm = new GoodsManager();

		gm.add(new Goods(10001, "王老吉", "饮品", 5, 10, "武汉"));
		gm.add(new Goods(10002, "棒棒糖", "零食", 1, 100, "武汉"));
		gm.add(new Goods(10003, "雪碧", "饮品", 3, 20, "武汉"));
		gm.add(new Goods(10004, "可口可乐", "饮品", 3, 50, "武汉"));
		gm.add(new Goods(10005, "老干妈", "干货", 10, 10, "武汉"));

		gm.show();
		System.out.println("根据编号显示商品的信息=================================");
		gm.findBySno1(10003);
		System.out.println("根据编号更改商品的价格、库存量====================================");
		gm.change(10005, 20, 100);
		gm.show();
		System.out.println("根据商品价格指定范围显示商品信息===============================");
		gm.assignShow(2);
		System.out.println("根据提供低于商品价格显示信息=========================");
		gm.showLowStore(30);
	}
}

测试:
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue是一种用于构建用户界面的JavaScript框架,它提供了一套简洁、灵活的开发方式,使得开发者可以轻松地构建交互性强、响应迅速的Web应用程序。MySQL是一种开源的关系型数据库管理系统,它被广泛应用于Web开发。将Vue和MySQL结合起来,可以实现一个功能强大的电商后台管理系统。 该电商后台管理系统可以具备以下功能: 1. 用户管理:实现用户的登录、注册、权限管理等功能,确保只有授权用户可以访问系统。 2. 商品管理:实现商品的添加、编辑、删除、分类等操作,方便管理员对商城商品进行管理。 3. 订单管理:实现对用户订单的管理,包括订单查询、修改订单状态、生成发货单等功能,提升订单处理效率。 4. 库存管理实现商品库存的管理,包括库存预警、库存调整、商品入库出库等功能,确保商品供应充足。 5. 数据统计:实现商品销售情况、订单数量、用户活跃度等数据的统计分析,为运营决策提供可视化报表。 在实现这个系统的过程,首先需要搭建一个后端服务,使用Node.js等服务器端技术,通过与MySQL数据库进行交互,提供RESTful API接口。然后,使用Vue框架进行前端开发,通过发起请求调用后端接口,获取数据并展示在页面上。通过使用Vue的组件化开发方式,可以有效地提高开发效率和项目可维护性。 总之,通过将Vue和MySQL相结合,我们可以实现一个功能强大的电商后台管理系统,方便管理员对商品、订单、用户等信息进行管理和统计分析,从而提升电商运营效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值