集合的工程案例详解

来源:互联网 发布:税控开票软件下载 编辑:程序博客网 时间:2024/04/30 02:19

/**

使用集合创建一个仓库添加货物的过程,并排序

*/



import java.util.ArrayList;
import java.util.List;


public class Shopper {


public static void main(String[] args) {
// 创建仓库
List<Producte> list = new ArrayList<>();
// 采购商品,数据仅供举例,不代表实际
Producte phone = new Producte(1, "手机", 2000, 100, true);
Producte computer = new Producte(2, "电脑", 4000, 50, true);
Producte fruit = new Producte(3, "水果", 8, 200, false);
Producte clothes = new Producte(4, "衣服", 500, 100, true);
Producte books = new Producte(5, "书本", 50, 100, false);
Producte virtual = new Producte(6, "虚拟商品", 20, 100, true);
// 添加商品
list.add(phone);
list.add(computer);
list.add(fruit);
list.add(clothes);
list.add(books);
list.add(virtual);
// 输出商品信息
for (int i = 0; i < list.size(); i++) {
Producte producte = list.get(i);
if (producte.getName().equals("水果")) {
fruit.setPrice(fruit.getPrice() - 1);
// list.set(2, fruit);//水果降价一元,手机加价100元;
}else if (producte.getName().equals("手机")) {
phone.setPrice(phone.getPrice() + 100);
// list.set(0, phone);
}//输出修改后的各个商品的信息
System.out.println(producte);
}
System.out.println("-------------------------------");
for (int i = 0; i < list.size(); i++) {
Producte producte = list.get(i);
if (producte.getCount()>90) {
System.out.println(producte);
}

}
}
}
0 0
原创粉丝点击