```
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;
import java.util.Scanner;
/*
* 商品管理员
*/
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("*********************");
System.out.println("请输入你要执行的操作");
Scanner scanner = new Scanner(System.in);
int gongnengbianhao = scanner.nextInt();
switch (gongnengbianhao) {
case 1:
System.out.println("查看商品信息");
chakan(); //调用查看商品信息的方法
break;
case 2:
System.out.println("新增商品信息");
break;
case 3:
System.out.println("删除商品信息");
break;
case 4:
System.out.println("卖出商品");
break;
case 5:
System.out.println("排行榜");
break;
case 6:
System.out.println("退出系统");
flag = false;
break;
default:
System.out.println("你输入的有误");
break;
}
}while (flag) ;
}
//查看商品信息
public void chakan(){
System.out.println("编号: \t 名称 \t 价格 \t 库存 \t 售出数量");
for ( int i = 0 ; i < articleSet.articles.length ; i++){
if (articleSet.articles[i] !=null){
articleSet.articles[i].print(i);
}
}
}
//添加商品
public void add(){
System.out.println("请输入商品名称");
String name = input.next();
System.out.println("请输入价格");
int price=input.nextInt();
System.out.println("请输入库存");
int amount=input.nextInt();
}
}
package com.company;
public class Demo {
public static void main(String[] args) {
ArticleManage articleManage = new ArticleManage();
articleManage.initial();
articleManage.startMenu();
}
}
```