酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

Java代码实现:全面查询Tony的优惠券领取、使用与失效情况

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 + "张优惠券已失效"); ``` ######[AI写代码神器 | 1117点数解答 | 2024-06-29 15:25:39]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]