当前位置:   article > 正文

用java实现简单库存管理系统_java中允许负库存数据库代码实现

java中允许负库存数据库代码实现
package text61;
import java.util.*;
 class Commodity {
    private String name;
    private String color;
    private double price;
    private int count;
    public Commodity() {}
      public Commodity(String name,String colour,double price,int count) {
        this();
        this.name = name;
        this.color = colour;
        this.price = price;
        this.count = count;
      }
      public String getName() {

        return name;
      }
      public void setName(String name) {

        this.name = name;
      }
    public String getColor() {

        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public double getPrice() {

        return price;
    }
    public void setPrice(double price) {

        this.price = price;
    }
    public int getCount() {

        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
}
public class Text61 {
    private static List commoditys = new ArrayList();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Commodity commodity = new Commodity("狼毫笔", "黑色", 18.5, 10);
        commoditys.add(commodity);
        int choose;
        while (true) {
            printMenu();
            choose = sc.nextInt();
            if (choose == 1) {
                Commodity cdy = new Commodity();
                System.out.print("商品名称:");
                String cdyName = sc.next();
                System.out.print("商品颜色:");
                String cdyColor = sc.next();
                System.out.print("商品价格:");
                double cdyPrice = sc.nextDouble();
                System.out.print("商品数量:");
                int cdyCount = sc.nextInt();
                cdy.setName(cdyName);
                cdy.setColor(cdyColor);
                cdy.setPrice(cdyPrice);
                cdy.setCount(cdyCount);
                addCommodity(cdy);
            } else if (choose == 2) {
                show(commoditys);
                System.out.println("\n");
            } else if (choose == 3) {
                System.out.println("请输入要删除的商品编号:");
                int i = sc.nextInt();
                delete(i);
            } else if(choose == 4) {
                System.out.println("退出库存管理系统~");
                System.exit(0);
            }
            else {
                System.out.println("输入有误,请重新输入!");
            }
        }
    }
    public static void delete(int i) {
        i--;
        commoditys.remove(i);
        System.out.println("出库成功!\n");
    }
    public static void addCommodity(Commodity cdy) {
        commoditys.add(cdy);
        System.out.println("商品已成功入库!\n");
    }
    public static void show(Collection commoditys) {
        Iterator<Commodity> it = commoditys.iterator();
        System.out.println("编号\t商品名称\t颜色\t价格\t库存");
        int n = 1;
        //使用Iterator接口迭代集合中的元素
        while (it.hasNext()) {
          Commodity cdy = it.next();
          System.out.println(n + "\t" + cdy.getName() + "\t" + cdy.getColor() + "\t" + cdy.getPrice() + "\t" + cdy.getCount());
           n++;
        }
        //使用foreach循环遍历集合中的元素
         //for(Object obj : commoditys) {
              // System.out.print(obj);
               // n++;
         // }
}
        public static void printMenu () {
            System.out.println("欢迎使用库存管理系统");
            System.out.println("----------------");
            System.out.println("1、商品入库");
            System.out.println("2、商品显示");
            System.out.println("3、删除商品");
            System.out.println("4、退出系统");
            System.out.println("-----------------");
            System.out.print("请输入你选择操作:");
        }
}
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/271138
推荐阅读
相关标签
  

闽ICP备14008679号