package edu.mama.ls16.homework;

    public class Buyer {
    private String ID;
    private String name;

    1. public Buyer(String ID, String name) {<br /> this.ID = ID;<br /> this.name = name;<br /> }
    2. public String getID() {<br /> return ID;<br /> }
    3. public String getName() {<br /> return name;<br /> }
    4. public void setName(String name) {<br /> this.name = name;<br /> }
    5. //以sep为分隔符,将Buyer内容拼接成字符串<br /> public String toString(String sep) {<br /> StringBuilder sb=new StringBuilder();<br /> sb.append(this.ID).append(sep).append(this.name);<br /> return sb.toString();<br /> }
    6. //使用Map,重写equals和hasCode方法<br /> @Override<br /> public boolean equals(Object obj) {<br /> if(this==obj)<br /> return true; //地址相等<br /> if(obj instanceof Buyer){<br /> Buyer other=(Buyer)obj;<br /> if(this.ID.equals(other.ID))<br /> return true; //ID相同<br /> }<br /> return false;<br /> }
    7. @Override<br /> public int hashCode() {<br /> return this.ID.hashCode();<br /> }<br />}