库存管理系统
1)要求完成货物的统计,货物内容由管理员手动输入
2)我们要对库存进行统计,添加了多少货物,要有数量的统计
3)允许对货物进行交易,卖出多少显示多少,同时显示剩余货物量
4)对于用户购买我们需要计算价格,有普通客户,还有会员,要求普通客户正 常计算,会员,打8折
构造方法
package DEMO; public class Goods { private String name; private int price; public Goods(String name, int price) { this.name = name; this.price = price; } @Override public String toString() { return "Goods{" + "name='" + name + '\'' + ", price=" + price + '}'; } public void setName(String name) { this.name = name; } public void setPrice(int price) { this.price = price; } public String getName() { return name; } public int getPrice() { return price; } }
代码块: package DEMO; import java.lang.annotation.Target; import java.util.ArrayList; public class demo{ private int count=0; private ArrayList<Goods> goodsList=new ArrayList<>(); //添加货物的方法 public void addGoods(Goods goods){ goodsList.add(goods); this.count=goodsList.size(); System.out.println("添加货物:"+goods+",库存:"+this.count); } //前几个数量进行买卖 public void sell(int n,boolean isVIP){ if(n>count){ return; } int totalPrice=0; for (int i = 0; i < n; i++) { totalPrice += this.goodsList.remove(i).getPrice(); } if(isVIP){ totalPrice= Double.valueOf(totalPrice*0.8).intValue(); } System.out.println("本次共消费:"+ totalPrice+",剩余库存"+(this.count-=n)); } public static void main(String[] args) { demo managerGoods = new demo(); managerGoods.addGoods(new Goods("袜子",10)); managerGoods.addGoods(new Goods("袜子",10)); managerGoods.addGoods(new Goods("袜子",10)); managerGoods.addGoods(new Goods("袜子",10)); managerGoods.addGoods(new Goods("袜子",10)); managerGoods.sell(2,true); managerGoods.addGoods(new Goods("pingguo",10)); } }