数组类
/* 商品的集合(仓库)*/
public class Demo02 {
Article[] articles = new Article[30];
}
商品类[给商品初始化]
/*商品类,对商品属性的封装*/
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;
}
}
代码类:
/*商品管理类*/
public class ArticleMange {
//创建一个实体的仓库对象 并实体化
Demo02 articleSet = new Demo02();
//初始化仓库,并放入起始商品
public void inital() {
Article xiaomi11 = new Article();
xiaomi11.setArticle("小米11", 30, 1999, 0);
Article xiaomi11pro = new Article();
xiaomi11pro.setArticle("小米11pro", 40, 2999, 0);
Article xiaomiUltra = new Article();
xiaomiUltra.setArticle("小米增强版", 50, 3999, 0);
articleSet.articles[0] = xiaomi11;
articleSet.articles[1] = xiaomi11pro;
articleSet.articles[2] = xiaomiUltra;
}
public void startMenu() {
boolean flag = true;
do {
System.out.println("*********************************");
System.out.println("1.查看商品信息");
System.out.printl