都实现
时间: 2024-02-13 15:04:06 浏览: 37
list类全部实现
5星 · 资源好评率100%
好的,下面是Truck类的实现代码:
```
public class Truck {
private ComputeWeight[] goods;
public Truck(ComputeWeight[] goods) {
this.goods = goods;
}
public double getTotalWeight() {
double totalWeight = 0;
for (ComputeWeight good : goods) {
totalWeight += good.computeWeight();
}
return totalWeight;
}
}
```
在Truck类中,我们存储了一个ComputeWeight类型的数组goods,表示该货车上的所有家电。getTotalWeight()方法就是遍历数组goods,计算所有货物的重量之和。
阅读全文