请高手给于程序案例!

解决方案 »

  1.   

    纯数据类,没什么需要测试的。
    public final class Address {
        public final String country;
        public final String province;
        public final String city;
        public final String street;
        public final String postcode;
        public Address(String country,String province,String city,String street,String postcode){
            this.country = country;
            this.province = province;
            this.city = city;
            this.street = street;
            this.postcode = postcode;
        }    @Override String toString(){
            return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
        }
    }
      

  2.   

     @Override String toString(){
            return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
        }
    这一句是什么意思!
      

  3.   

        @Override String toString(){
            return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
        }    @Override public String toString(){
            return String.format("Address[country:%s, province:%s, city:%s, street:%s, postcode:%s]",country,province,city,street,postcode);
        }
    少写了 public。 类实例的字符串表示。
    System.out.println(new Address(...));会调用 toString 方法。
      

  4.   

    应该在加上 hashCode equals 方法:@Override public int hashCode(){
        return this.toString().hashCode();
    }@Override public boolean(Object o){
        if(o == null) return false;
        if(o == this) return true;
        if(o.getClass() == Address.class){ return this.toString().equals(((Address)o).toString());
        return false;
    }
      

  5.   

    晕,又少写了方法名 equals
      

  6.   

    测试类就用public static void main方法,来创建这个类好了。Address address = new Address("","",..."");
    你就去一个个的把内容加上就好了