这是我到目前为止所拥有的,包括测试课我只是不确定如何比较两个团队这是作业......团队只有一个属性,球队名称(例如巴塞罗那)
包括以下这些:
构造函数
获取器/评估器方法
修改器/设置器方法
toString 方法
等于方法
班组
public class Team {
private String name;
public Team(String name) { // Constructor
this.name = name;
}
public void setName(String name) { // The Setter set's the name
this.name = name;
}
public String getName() { // The Getter get's the the name
return name;
}
@Override
public String toString() { // This returns a String object
return "The team name is " + name;
}
@Override
public boolean equals(Object o) {
if (o instanceof Team) {
Team t = (Team) o;
if (t.getName().equalsIgnoreCase(getName())) { //I'm not sure what i'm missing here
return true;
}
else {
return false;
}
}
else {
return false;
}
}
}
测试班
public class TeamMain {
public static void main(String[] args) {
Team team = new Team("ManUnited");
Team team2 = new Team("ManCity");
System.out.println(team.equals("ManUnited"));
System.out.println(team2.equals("ManCity"));
System.out.println(team.getName());
team.setName("ManCity");
System.out.println(team.toString());
}
}