package com.lch.olympic;
public enum CompetitionResult {
WIN {
public String getResult() {
return "升国旗,奏国歌,颁奖!";
}
},
DRAW {
public String getResult() {
return "国旗平置,颁奖!";
}
},
LOSE {
public String getResult() {
return "奥运精神的体现,精神的胜者!";
}
};
abstract String getResult();
}
package com.lch.olympic;
public interface IOlympicComp {
String winGame();
}
package com.lch.olympic;
return CompetitionResult.DRAW.getResult();
}
return CompetitionResult.LOSE.getResult();
}
return CompetitionResult.WIN.getResult();
}
package com.lch.olympic;
protected String nation;
CHINA {
public String getNationName() {
return "CHINA";
}
},
OTHERS {
public String getNationName() {
return "OTHERS";
}
};
abstract String getNationName();
}
private LondonOlympic() {
}
* 构造子
*
* @param nation国家
*
* **/
public LondonOlympic(String nation) {
this.nation = nation;
}
public String drawGame() {
String result;
if (Nation.CHINA.getNationName().equals(nation)) {
result = "国旗放其它国家下面!";
} else {
result = CompetitionResult.DRAW.getResult();
}
return result;
}
public String loseGame() {
String result;
if (Nation.CHINA.getNationName().equals(nation)) {
result = "消极比赛,取消比赛资格!";
} else {
result = CompetitionResult.LOSE.getResult();
}
return result;
}
public String winGame() {
String result;
if (Nation.CHINA.getNationName().equals(nation)) {
result = "使用兴奋剂?!";
} else {
result = CompetitionResult.WIN.getResult();
}
return result;
}
package com.lch.olympic;
private final String CHINA = "CHINA";
private final String NOT_CHINA = "CDA";
LondonOlympic olympic = new LondonOlympic(CHINA);
System.out.println("中国赢得比赛:" + olympic.winGame());
System.out.println("中国平了比赛:" + olympic.drawGame());
System.out.println("中国输了比赛:" + olympic.loseGame());
}
LondonOlympic olympic = new LondonOlympic(NOT_CHINA);
System.out.println("非中国赢得比赛:" + olympic.winGame());
System.out.println("非中国平了比赛:" + olympic.drawGame());
System.out.println("非中国输了比赛:" + olympic.loseGame());
}
Test t = new Test();
System.out.println("\n*********** London Olympic ***********\n");
t.comp4China();
System.out.println("\n=========== 楚河 汉界 ===========\n");
t.comp4Other();
System.out.println("\n*********** London Olympic ***********\n");
}
}