1. 查询出tony共领取了多少优惠券 ```java // Assuming that the coupon data is stored in a List of Coupon objects and each Coupon object has a field "receiver" to store the recipient's name int tonyCouponCount = 0; for (Coupon coupon : couponList) { if (coupon.getReceiver().equals("Tony")) { tonyCouponCount++; } } System.out.println("Tony共领取了" + tonyCouponCount + "张优惠券"); ``` 2. 查询出tony还有多少优惠券未使用,显示优惠券id,优惠券名称,优惠价格,优惠状态 ```java // Assuming that the Coupon class has fields "id", "name", "price" and "status" to store the coupon details int unusedCouponCount = 0; for (Coupon coupon : couponList) { if (coupon.getReceiver().equals("Tony") && coupon.getStatus().equals("unused")) { System.out.println("优惠券id:" + coupon.getId() + ",优惠券名称:" + coupon.getName() + ",优惠价格:" + coupon.getPrice() + ",优惠状态:" + coupon.getStatus()); unusedCouponCount++; } } System.out.println("Tony还有" + unusedCouponCount + "张优惠券未使用"); ``` 3. 显示tony还有多少优惠券未使用,多少优惠券已使用,多少优惠券已失效 ```java int unusedCount = 0; int usedCount = 0; int expiredCount = 0; for (Coupon coupon : couponList) { if (coupon.getReceiver().equals("Tony")) { if (coupon.getStatus().equals("unused")) { unusedCount++; } else if (coupon.getStatus().equals("used")) { usedCount++; } else if (coupon.getStatus().equals("expired")) { expiredCount++; } } } System.out.println("Tony还有" + unusedCount + "张优惠券未使用," + usedCount + "张优惠券已使用," + expiredCount + "张优惠券已失效"); ``` [2024-06-29 15:25:39 | AI写代码神器 | 1117点数解答]