根据课堂讲解的柜台管理程序自己重新设计
(根据脑海的思路,自己重新写,否则没有意义)
(如果还无法独立重新写,就先对着代码再写一遍,边写边理解)
1.初步设计
最基本的代码
不包含任何的健壮性和重复性判断
能实现需求即可
不写工具类和异常处理等等
最终能实现基本的运行和操作
2.健壮性调整
增加工具类InputUtils来解决输入异常的问题
show();
增加商品数量为0时的提示
不输出null商品
delete();
无(根据自己的需求)
add();
增加商品数量已满的提示
增加商品编号不能重复的判断
update();
根据商品编号(输入要修改的商品编号)
修改商品的价格
要求:从设计之初,把柜台商品管理的设计概要和需求,以及后续
一步一步如何设计的,文字+代码
1.初步设计的过程和代码,以及测试结果
商品类:
public class Goods {
private int id; //商品编号
private String goodsName; //商品名称
private double price; //商品价格
private String desc; //商品描述
public int getId() {
return id;
}
public String getGoodsName() {
return goodsName;
}
public double getPrice() {
return price;
}
public String getDesc() {
return desc;
}
public void setId(int id) {
this.id = id;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public void setPrice(double price) {
this.price = price;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Goods(int id, String goodsName, double price, String desc) {
this.id = id;
this.goodsName = goodsName;
this.price = price;
this.desc = desc;
}
public Goods() {
}
@Override
public String toString() {
return "Goods{" +
"编号=" + id +
", 商品名称='" + goodsName + '\'' +
", 价格=" + price +
", 描述='" + desc + '\'' +
'}';
}
}
最开始设计的柜台:
public class Counter {
int num;
Goods[] goodses = new Goods[10];//
public Counter(){
this.goodses[0]=new Goods(1001,"巧克力",25,"美味可口,恋爱必备!");
this.goodses[1]=new Goods(1002,"卫龙辣条",1,"隔壁小孩馋哭了!");
this.goodses[2]=new Goods(1003,"钟薛高",18,"雪糕刺客!!!!");
num=3;
}
public void show(){
System.out.println("------------- 柜台的商品列表 --------------");
if(this.num==0){
System.out.println("警告:柜台没有商品..");
return;
}
for (int i = 0;