package train2;
public class store {
public String id;
public String name;
public double price;
public int count;
public store() {
}
public store(String id, String name, double price, int count) {
this.id = id;
this.name = name;
this.price = price;
this.count = count;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
package train2;
public class storeTest {
public static void main(String[] args) {
//1.创建一个数组
store[] arr = new store[3];
//2.创建三个商品对象
store s1 = new store("001", "小米", 6999.0, 1500);
store s2 = new store("002", "大米", 69.0, 50000);
store s3 = new store("003", "水杯", 99.0, 66000);
//3.把商品放到数组中
arr[0] = s1;
arr[1] = s2;
arr[2] = s3;
//4.遍历
for (int i = 0; i < arr.length; i++) {
store Store = arr[i];
System.out.println(Store.getId() + Store.getName() + Store.getPrice() + Store.getCount()+"\t");
}
}
}