商店后台管理系统

···

package com.company;
public class Article {

//把常用的属性 封禁
public String name;    //名字
public int amount ;    //库存
public double price;   //单价
public int number;     //售出数量

public  void print(int index) {
    System.out.println(index + "\t" + name + "\t" +amount + "\t" + price + "\t" + number);
}
//
public void setArticle(String mingzi , int kucun , double danjia , int shouchu){
    name = mingzi;
    amount = kucun;
    price = danjia;
    number = shouchu;
}

}

package com.company;
/* 商品集合 便于管理多个商品,ArticleSet 商品集合*/
public class ArticleSet {

// 准备一个数组,里面存储商品,作为仓库
Article [] articles = new Article[30];

}

package com.company;
/* 商品管理员 */
public class ArticleManage {

// 创建一个商品集合(仓库)实例
ArticleSet articleSet = new ArticleSet();

//对新建的仓库进行初始化
public void initial() {
    //创建商品
    Article xiaomi11 = new Article();
    xiaomi11.setArticle("小米11", 50, 2999, 1);

    Article xiaomi11pro = new Article();
    xiaomi11.setArticle("小米pro", 30, 3999, 2);

    //把商品放入仓库中
    articleSet.articles[0] = xiaomi11;
    articleSet.articles[1] = xiaomi11pro;
}

//起始菜单
public void startMenu() {
    boolean flag = true;
    do {
        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("*********************");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要执行的操作");

        int gongnengbianhao = scanner.nextInt();
        switch (gongnengbianhao) {
            case 1:
                System.out.println("查看商品信息");
                chakan();  //调用查看商品信息的方法
                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("排行榜");
                paihangbang();
                break;
            case 6:
                System.out.println("退出系统");
                exit();
                flag = false;
                break;
            default:
                System.out.println("你输入的有误");
                break;

        }
        }while (flag) ;
    }

public void exit(){
        System.out.println("退出");
    }

public void paihangbang(){
    //排序(冒泡排序)
      for (int i = 0 ; i < articleSet.articles.length-1 ; i ++){
          for ( int j = 0 ; j < articleSet.articles.length - i -1 ; j ++){
              //  如果当前元素的纸币后面的元素值小 那么和后面的元素交换位置
              if(articleSet.articles[j] != null && articleSet.articles[j+1]!=null){
                  if (articleSet.articles[j].number < articleSet.articles[j+1].number){
                      // 交换位置
                      Article tempArticle = articleSet.articles[j];
                      articleSet.articles[j] = articleSet.articles[j+1];
                      articleSet.articles[j+1] = tempArticle;
                  }
              }

          }
      }
        System.out.println("***********排行榜**********");
        System.out.println("名次 \t 销售数量 \t 商品名称");
        for (int i = 0 ; i < articleSet.articles.length ; i ++){
            System.out.println((i+1) +"\t"+articleSet.articles[i].number+"\t"+articleSet.articles[i].name);
        }
}

//卖出商品
public void sell(){
    /*
     sout(卖出名称)
       scanner = new Scanner
         name = sc.next()
          for(; int i < length ;)
                articles[i] .equals( name ) )
                 接受卖出的数量
                int num = sc.nextInt();
                if (num 

package com.company;
public class Demo {

public static void main(String[] args) {
    ArticleManage articleManage = new ArticleManage();
    articleManage.initial();
    articleManage.startMenu();
}

}

···

你可能感兴趣的:(商店后台管理系统)