购物车Q14
创建一个 Java 文件 叫 Cart
然后先抄上下面的代码
1 2 3 4 5 6 7 8 9 public class Cart{ public static void main(String[] args) { new Cart().run(); } public void run() { // Section 1 } // Section 2}
按着下面的描述,逐一在 Section 2 中声明函数,
并在 Section 1 写对应的调用代码,调用
total(prices: int[], quantities: int[]): int
函数有两个参数,一个参数是消费者购买的所有商品的单价,prices
还有一个消费者购买的这些商品对应的数量,quantities
需要这次的总价
约束
prices 和 quantities 的长度应该是一样的
adjust(total: int): int
根据总价计算最终的商品价格,计算规则
不足 100,加 16 元 运送费
超过 200,减 20 元 优惠
count(prices: int[], quantities: int[]): int
函数有两个参数,一个参数是消费者购买的所有商品的单价,prices
还有一个消费者购买的这些商品对应的数量,quantities
需要返回数量总数