Where is the Java bug in my constructor code for this KnockKnockProtocol class? <p>I'm studying the following client/server code called <a href="https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html" rel="nofollow">KnockKnockServer and KnockKnockClient.</a> It also has a helper class called <a href="https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockProtocol.java" rel="nofollow">KnockKnockProtcol</a>, which is responsible for the order of KnockKnock jokes.</p> <p>I want to modify it so that you can start the program at a specific joke. As it is right now, you have to start with the first joke. </p> <p>This is what tried for KnockKnockProtocol:</p> <pre><code>public class KnockKnockProtocol { int ourstep; public KnockKnockProtocol (int step) { this.ourstep = step; } 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; int currentJoke = ourstep; //we initialize the step here private String[] clues = { "Turnip", "Little Old Lady", "Atch", "Who", "Who" }; private String[] answers = { "Turnip the heat, it's cold in here!", "I didn't know you could yodel!", "Bless you!", "Is there an owl in here?", "Is there an echo in here?" }; public String processInput(String theInput) { String theOutput = null; if (state == WAITING) { theOutput = "Knock! Knock!"; state = SENTKNOCKKNOCK; } else if (state == SENTKNOCKKNOCK) { if (theInput.equalsIgnoreCase("Who's there?")) { theOutput = clues[currentJoke]; state = SENTCLUE; } else { theOutput = "You're supposed to say \"Who's there?\"! " + "Try again. Knock! Knock!"; } } else if (state == SENTCLUE) { if (theInput.equalsIgnoreCase(clues[currentJoke] + " who?")) { theOutput = answers[currentJoke] + " Want another? (y/n)"; state = ANOTHER; } else { theOutput = "You're supposed to say \"" + clues[currentJoke] + " who?\"" + "! Try again. Knock! Knock!"; state = SENTKNOCKKNOCK; } } else if (state == ANOTHER) { if (theInput.equalsIgnoreCase("y")) { theOutput = "Knock! Knock!"; if (currentJoke == (NUMJOKES - 1)) currentJoke = 0; else currentJoke++; state = SENTKNOCKKNOCK; } else { theOutput = "Bye."; state = WAITING; } } return theOutput; } } </code></pre> <p>And in the Server class, I call the KnockKnockProtocol like this :</p> <pre><code> /* omitting boilerplate code */ String inputLine, outputLine; // Initiate conversation with client KnockKnockProtocol kkp = new KnockKnockProtocol(2); outputLine = kkp.processInput(null); out.println(outputLine); while ((inputLine = in.readLine()) != null) { outputLine = kkp.processInput(inputLine); out.println(outputLine); if (outputLine.equals("Bye.")) break; </code></pre> <p>The problem is that , when I run my code I am always starting with the "Turnip" joke. How do I make it so that I can start at an arbitrary joke within the list of jokes? I can see that the joke is controlled by the <code>clues</code> array, but after that I'm not seeing it. thanks</p>