package co.hp.object.good;
public class Goods {
//属性
private int id;
private String goodsName;
private float price;
private String desc;
//get set方法
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
//构造器,无参构造,有参构造
public Goods() {
}
public Goods(int id, String goodsName, float price, String desc) {
this.id = id;
this.goodsName = goodsName;
this.price = price;
this.desc = desc;
}
//tostring方法
@Override
public String toString() {
return "Goods{" +
"id=" + id +
", goodsName='" + goodsName + '\'' +
", price=" + price +
", desc='" + desc + '\'' +
'}';
}
}
package co.hp.object.good;
import java.util.Scanner;
public class Counter {
//柜台商品列表,固定10个商品位置
Goods[] Goods = new Goods[10];
int num = 0;
public Counter(){
this.Goods[0] = new Goods(1001,"巧克力",25,"美味可口,恋爱必备!");
this.Goods[1] = new Goods(1002,"卫龙辣条",1,"隔壁小孩馋哭了