Giải thích đề bài sử dụng compareTo()
Program FSIS of a flower shop captures and processes data about an entity named Customer and a specific type of Customer named HighEarner. The former represents customers that are of interest to the shop, while the latter represents wealthy customers whose income are above a given threshold. Figure 1 shows the concept class diagram of FSIS. Table 1 lists the attribute design details of Customer and HighEarner. Note that attribute income is specific to HighEarner. To ease listing of customer objects, program FSIS requires that Customer realises an interface named Comparable. This interface is provided by Java. The implementation of the method Comparable.compareTo must compare two Customers by name.
mình không hiểu là cái interface comparable thì sẽ so sánh cái gì, so sánh giữa HighEarn vs nomal customer à??
So sánh giữa 2 khách hàng bằng tên thôi.
Đại loại như này:
Nói chung là cái Interface Comparable và Comparator là 2 cái Interface cung cấp cho bạn các method so sánh: compareTo, equals and compare. Để sử dụng các method này bạn cần implements 2 cái interface đó, nó sẽ cung cấp cho bạn các method này theo kiểu mặc định.
Bạn cũng có thể Override lại 2 các phương thức này để so sánh dựa theo ý của bạn.
This post was flagged by the community and is temporarily hidden.