package OOPtest4.java文件;
/**
* 返回PlainText格式的队伍信息的类
*
* @author "HuangFan"
* @version 1.0
*
*/
public class PlainTextTeamFormatter implements TeamFormatter{
private final static String NEW_LINE = System.getProperty("line.separator");
static private PlainTextTeamFormatter singletonInstance = null;
/**
* 获取类PlainTextTeamFormatter的单一实例
*
* @return 类PlainTextTeamFormatter的单一实例
*
*/
static public PlainTextTeamFormatter getSingletonInstance() {
if(singletonInstance == null) {
singletonInstance = new PlainTextTeamFormatter();
}
return singletonInstance;
}
/**
* 构造函数声明为私有,使其他类不能创建该类的实例
*
*/
private PlainTextTeamFormatter() {
}
@Override
/**
* 该方法返回队伍信息的一个PlainText格式的表示
*
* @param team
* @return 队伍信息的PlainText表示
*
*/
public String formatTeam(Team team) {
// TODO Auto-generated method stub
String out = "Team {"+NEW_LINE+" teamId : "+team.getTeamId()+NEW_LINE;
out += " teamName : "+team.getTeamName()+NEW_LINE;
out += " department : "+team.getDepartment()+NEW_LINE;
out += " creator {"+NEW_LINE;
out += " id : "+team.getCreator().getId()+NEW_LINE;
out += " name : "+team.getCreator().getName()+NEW_LINE;
out += " phoneNo : "+team.getCreator().getPhoneNo()+NEW_LINE;
out += " email : "+team.getCreator().getEmail()+NEW_LINE;
out += " studentNo : "+team.getCreator().getStudentNo()+NEW_LINE;
if(team.getCreator().getGender() == true) {
out += " gender : "+"女"+NEW_LINE;
}
else {
out += " gender : "+"男"+NEW_LINE;
}
out += " grade : "+team.getCreator().getGrade()+NEW_LINE;
out += " department : "+team.getCreator().getDepartment()+NEW_LINE;
out += " }"+NEW_LINE;
out += " studentList {"+NEW_LINE;
for(Student student : team.students) {
out += " student {"+NEW_LINE;
out += " id : "+student.getId()+NEW_LINE;
out += " name : "+student.getName()+NEW_LINE;
out += " phoneNo : "+student.getPhoneNo()+NEW_LINE;
out += " email : "+student.getEmail()+NEW_LINE;
out += " studentNo : "+student.getStudentNo()+NEW_LINE;
if(student.getGender() == true) {
out += " gender : "+"女"+NEW_LINE;
}
else {
out += " gender : "+"男"+NEW_LINE;
}
out += " grade : "+student.getGrade()+NEW_LINE;
out += " department : "+student.getDepartment()+NEW_LINE;
out += " }"+NEW_LINE;
}
out += " }"+NEW_LINE;
out += " teacherList {"+NEW_LINE;
for(Teacher teacher : team.teachers) {
out += " teacher {"+NEW_LINE;
out += " id : "+teacher.getId()+NEW_LINE;
out += " name : "+teacher.getName()+NEW_LINE;
out += " phoneNo : "+teacher.getPhoneNo()+NEW_LINE;
out += " email : "+teacher.getEmail()+NEW_LINE;
out += " teacherNo : "+teacher.getTeacherNo()+NEW_LINE;
out += " department : "+teacher.getDepartment()+NEW_LINE;
out += " }"+NEW_LINE;
}
out += " }"+NEW_LINE;
out += "}"+NEW_LINE;
return out;
}
}
这是我今天写的一部分代码,作为本周第一次打卡 |