<分区>
public String toString() {
String info = "";
String courseInfo = this.getCourseInfo();
if("".equals(courseInfo)) {
courseInfo = "None";
}
info += "--------------------------------------------------\n";
info += "Student Name: " + this.name + "\n";
info += "Student Address: " + this.address + "\n";
info += "Student #: " + this.studentNumber + "\n";
info += "Student Login ID: " + this.loginID + "\n";
info += "Courses taken:" + "\n";
info += courseInfo + "\n";
info += "GPA: " + this.getGPA() + "\n";
info += "--------------------------------------------------\n";
return info;
}
有人告诉我,这是一个糟糕的 toString 方法,因为它应该在一行上输出诊断信息,或者如果有意义的话,输出单个文字值。我真的不明白。我应该只打印所有实例变量并让用户决定它是什么吗?