【发布时间】:2021-09-01 06:17:31
【问题描述】:
有人可以帮我在 JAVA 中实现一个获取书店销量最高的 50 本书的方法吗?
这是Bookstore 类:
public class Bookstore implements Serializable {
private static final long serialVersionUID = -3099048826035606338L;
private boolean populated;
private final List<Country> countryById;
private final Map<String, Country> countryByName;
private final List<Address> addressById;
private final Map<Address, Address> addressByAll;
private final List<Customer> customersById;
private final Map<String, Customer> customersByUsername;
private final List<Author> authorsById;
private final List<Book> booksById;
private final List<Cart> cartsById;
private final List<Order> ordersById;
private final LinkedList<Order> ordersByCreation;
OrderLine 是另一个带有订单详细信息的类,例如:
private final Book book;
private final int qty;
private final double discount;
private final String comments;
我开始这样做:(我必须考虑订单状态已发货和书的主题),但我不知道这是否正确或下一步该怎么做,例如,如何将数量相加bookId 并订购 bestSellers 列表:
public List<Book> getBestSellers(String subject) {
ArrayList<Book> bestSellers = new ArrayList<Book>();
for (Order order : ordersById) {
if (order.getStatus().equalsIgnoreCase("SHIPPED")) {
for (int i=0; i<order.getLines().size(); i++){
【问题讨论】:
-
或许可以创建一个 Map,以 Book 对象为键,以 Integer 为值。
标签: java list sorting arraylist