A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

郝梦伟

初级黑马

  • 黑马币:

  • 帖子:

  • 精华:

© 郝梦伟 初级黑马   /  2019-9-22 12:47  /  957 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class Computer {
     private  String  brand;
     private double price;
     private String size;

    public Computer() {
    }

    public Computer(String brand, double price, String size) {
        this.brand = brand;
        this.price = price;
        this.size = size;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "brand='" + brand + '\'' +
                ", price=" + price +
                ", size='" + size + '\'' +
                '}';
    }
}
public class Test {
    //主方法
    public static void main(String[] args) {
        //创建一个集合
        ArrayList<Computer> list = new ArrayList<Computer>();
        Computer  c1= new Computer("Apple", 11980.0, "13寸");
        Computer  c2= new Computer("Dell", 5200.0, "15.5寸");
        Computer  c3= new Computer("Acer", 4999.0, "15寸");
        //将对象添加到集合中
        list.add(c1);
        list.add(c2);
        list.add(c3);
        for (int i = 0; i <list.size() ; i++) {
            Computer computer = list.get(i);
            if(computer.getPrice()>5000){
                System.out.println(computer.getBrand()+","+computer.getPrice()+","+computer.getSize());
            }
        }

    }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马