第27天

发布时间 2023-07-28 10:47:36作者: 七安。

 

package 两个对象数组;

public class Goods {
    private String id;
    private String name;
    private double price;
    private int count;

    public Goods(String id, String name, double price, int count) {
        super();
        this.id = id;
        this.name = name;
        this.price = price;
        this.count = count;
    }

    public Goods() {
        super();
        // TODO Auto-generated constructor stub
    }

    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 两个对象数组;

public class GoodsTest {
    public static void main(String[] args) {

        Goods[] arr = new Goods[3];
        Goods g1 = new Goods("001", "红米K50 Pro", 2567.00, 30);
        Goods g2 = new Goods("002", "红米K50", 2337.00, 31);
        Goods g3 = new Goods("003", "iPhone 15 ProMax 暗夜紫", 16032.00, 2);
        arr[0] = g1;
        arr[1] = g2;
        arr[2] = g3;
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getId() + arr[i].getName() + arr[i].getPrice() + arr[i].getCount());
        }
    }
}
001红米K50 Pro2567.030
002红米K502337.031
003iPhone 15 ProMax 暗夜紫16032.02