2021-04-15


public class Article {
    public String name;  //商品名称
    public int amount;//商品库存数量
    public double price; //商品价格
    public int number;//商品售出数量
    public void setArticle(String mingzi ,int shuliang , double danjia, int shouchushuliang) {
        name = mingzi;
        amount = shuliang;
        price = danjia;
        number = shouchushuliang;
    }

    //商品信息展示
    public void print(int index) {
        System.out.println(index+"\t"+name+"\t"+price+"\t"+amount+"\t"+number);
    }
}


public class ArticleManage {
    ArticleSet articleSet = new ArticleSet();
    Scanner input = new Scanner(System.in);

    //初始化商品

    public  void initial() {
        Article xiaoMi9 = new Article();
        xiaoMi9.setArticle("小米9",60,2799,0);
        Article xiaoMi8 = new Article();
        xiaoMi8.setArticle("小米8",40,2049,0);
        Article Redmi7 = new Article();
        Redmi7.setArticle("Redmi7",80,699,0);
        Article xiaomi6x = new Article();
        xiaomi6x.setArticle("小米6x",100,749,0);

        articleSet.articles[0] = xiaoMi9;
        articleSet.articles[1] = xiaoMi8;
        articleSet.articles[2] = Redmi7;
        articleSet.articles[3] = xiaomi6x;
    }

    //菜单切换
    public void startMenu() {
        boolean flag = true;  //是否继续操作
        do {
            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("5. 商品销售排行榜");
            System.out.println("6. 退出");
            System.out.println("-------------------------");
            System.out.println("请选择要执行的操作");
            int xuanze = input.nextInt();
            switch (xuanze) {
                case 1:
                    System.out.println("查看商品信息");
                    search();
                    break;
                case 2:
                    System.out.println("新增商品信息");
                    add();
                    break;
                case 3:
                    System.out.println("删除商品信息");
                    delete();
                    break;
                case 4:
                    System.out.println("卖出商品");
                    sell();
                    break;
                case 5:
                    System.out.println("商品销售排行榜");
                    break;
                case 6:
                    System.out.println("退出");
                    flag = false;
                    break;
                default:
                    System.out.println("输入不符合要求请重新选择");
                    break;
            }
        }while(flag);
    }
    //商品查看
    public void search(){
        System.out.println("编号\t名称\t价格\t库存\t售出");
        for (int i=0; i

你可能感兴趣的:(2021-04-15)