📄 serverprotocoltest.java
字号:
package ch07.section07;
public class ServerProtocolTest {
private static final int WAITING = 0;
private static final int SENTKNOCKKNOCK = 1;
private static final int SENTCLUE = 2;
private static final int ANOTHER = 3;
private static final int NUMJOKES = 5;
private int state = WAITING;
private int currentJoke = 0;
private String[] clues = {
"1", "2", "3", "4", "5"};
private String[] answers = {
"6",
"7",
"8",
"9",
"10"};
public String processInput(String theInput) {
String theOutput = null;
if (state == WAITING) {
theOutput = "Holle";
state = SENTKNOCKKNOCK;
}
else if (state == SENTKNOCKKNOCK) {
if (theInput.equalsIgnoreCase("你好!")) {
theOutput = clues[currentJoke];
state = SENTCLUE;
}
else {
theOutput = "8888888";
}
}
else if (state == SENTCLUE) {
if (theInput.equalsIgnoreCase(clues[currentJoke] + " string98")) {
theOutput = answers[currentJoke] + " yyyyy";
state = ANOTHER;
}
else {
theOutput = "rrrrrr" +
"hhhhhhhhhh";
state = SENTKNOCKKNOCK;
}
}
else if (state == ANOTHER) {
if (theInput.equalsIgnoreCase("y")) {
theOutput = "565656";
if (currentJoke == (NUMJOKES - 1)) {
currentJoke = 0;
}
else {
currentJoke++;
}
state = SENTKNOCKKNOCK;
}
else {
theOutput = "Bye.";
state = WAITING;
}
}
return theOutput;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -