目录
一.题目
定制排序作业
设计Cat、Dog两个类。
Cat类有以下属性
String name ;
double weight ;
Dog类有以下属性
String type ;
double weight ;
使用定制排序法,来实现TreeSet 能存入
Cat、Dog两种类型对象,并能以weight 进行排序。
提示:这里使用了面向对象的一种设计手法。
二.提示
需要解决的问题:TreeSet实现可以存入两种类型
比较器的两种使用
继承
三.代码
Animal.java
package com.gongsi.cn;
import java.util.Comparator;
//
public class Animal implements Comparator<Animal>{
double weight;
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;