电车难题(Trolley Problem)
时间: 2023-05-26 11:05:28 浏览: 72
电车难题是一种伦理学上的思想实验。情境为一个电车向前行驶,无法控制停止,将会撞上五个人。你站在一个岔道上,可以通过操作一个开关将电车转到另一条轨道上,但那条轨道上也有一名人。你将面临以下两种选择:
1. 不操作开关,让电车继续往前撞击五个人。
2. 操作开关,将电车转向另一条轨道上,只撞击一名人。
这个难题引发了许多关于伦理学、道德和责任的思考和讨论。不同人在面临这个难题时可能会有不同的反应和选择,但这也反映了人类价值观和道德标准的多样性。
相关问题
List<Trolley> trolleys = new ArrayList<>();
这是一个Java代码片段,它创建了一个名为 "trolleys" 的空 ArrayList,该列表将存储类型为 "Trolley" 的元素。可以使用以下语法向此列表添加元素:
```
Trolley trolley = new Trolley(); // 创建 Trolley 对象
trolleys.add(trolley); // 将 Trolley 对象添加到 trolleys 列表中
```
也可以使用以下语法从列表中获取元素:
```
Trolley firstTrolley = trolleys.get(0); // 获取 trolleys 列表中的第一个元素
```
需要注意的是,添加到列表中的元素必须是类型为 "Trolley" 的对象,否则会导致编译错误。
public Trolley confirmIsExist(Trolley trolley) { Trolley t = null; try { t = (Trolley)this.qRunner.query("select * from trolley where uid = ? and gid = ? and orders_number is null", new BeanHandler<Trolley>(Trolley.class), new Object[]{trolley.getUid(), trolley.getGid()}); } catch (SQLException var4) { var4.printStackTrace(); } return t; }
这段代码是一个方法,方法名为`confirmIsExist`,返回一个`Trolley`对象。该方法的目的是查询购物车中某个商品是否存在于数据库中,如果存在则返回该商品的信息,否则返回`null`。方法中使用了`Apache`的`DbUtils`库,通过`query`方法执行一条`SQL`语句,查询符合条件的数据,并使用`BeanHandler`将查询结果映射成`Trolley`类的实例。其中`?`是占位符,被`new Object[]{trolley.getUid(), trolley.getGid()}`所代替。如果查询过程中出现`SQLException`异常,则打印异常信息。最后返回查询结果。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<c:set var="sum_price" value="0"></c:set> <c:set var="goods_count" value="0"></c:set> <c:set var="tids" value="#"></c:set> <c:forEach items="${trolleys }" var="trolley"> <c:set var="tids" value="${tids }#${trolley.tid }"></c:set>
${trolley.goods.gname } ${trolley.goods.color } ${trolley.goods.price }元 - <input type="text" value="${trolley.number }" id="num"> <c:set var="goods_count" value="${goods_count + trolley.number }"></c:set> + <c:set var="sum_price" value="${sum_price + trolley.goods.price * trolley.number }"></c:set> ${trolley.goods.price * trolley.number }元 删除 </c:forEach>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)