I'm making a system where the server asks questions to the client and the client responds. Then the marks out of 3 that the client had got is to be displayed. Everythign in my code works to the way i want it to, except the display of the marks. I have made arrays in which the final mark should relate to. But they always give the same output which is "You got 0/3 correct, Try Harder." instead of whichever one its meant to print out, someone help me, ive spent hours on this. I would also love to ass a password to the system.
PROTOCOL
import java.net.*; import java.io.*; public class MathsProtocol { private static final int FIRSTstate = 0; private static final int SECONDstate = 1; private static final int THIRDstate = 2; private static final int FOURTHstate = 3; private static final int FIFTHstate = 4; private static final int SIXTHstate = 5; private static final int SEVENTHstate = 6; private static final int NUMques = 7; private int state = FIRSTstate; private int currentQues = 0; private String[] clues = { "You got 0/3 correct, Try Harder.", "You got 1/3 correct, You could do better.", "You got 2/3 correct, Average.", "You got 3/3 correct, You smart pants.",}; public String processInput(String theInput) { String theOutput = null; int Q1Res = 0; int Q2Res = 0; int Q3Res = 0; int TOTALRes = 0; //QUESTION 1----------------------------------------------------------------------------- if (state == FIRSTstate) { theOutput = ("Q1: (A + B)*(A+B)" + " 1.A*A+B*B "+ " 2.A*A+A*B+B*B " + " 3.A*A+2*A*B+B*B "); state = SECONDstate; } else if (state == SECONDstate) { if (theInput.equalsIgnoreCase("3")) { theOutput = "That is the correct answer"; Q1Res++; state = THIRDstate; } else { theOutput = " WRONG!! TRY AGAIN"; } // QUESTION 2----------------------------------------------------------------------------- if (state == THIRDstate) { theOutput = "CORRECT!! Q2: (A+B)*(A-B) =" + " 1) A*A+2*B*B" + " 2) A*A-B*B " + " 3) A*A-2*A*B+B*B"; state = FOURTHstate; } //---------- } else if (state == FOURTHstate) { if (theInput.equalsIgnoreCase("2")) { theOutput = "That is the correct answer"; state = FIFTHstate; } else { theOutput = " WRONG!!Try again "; state = FOURTHstate; } } //QUESTION 3----------------------------------------------------------------------------- if (state == FIFTHstate) { theOutput = ("CORRECT!! Q3: sin(x)*sin(x) + cos(x)*cos(x) 1? 2? or 3?"); state = SIXTHstate; } else if (state == SIXTHstate) { if (theInput.equalsIgnoreCase("1")) { theOutput = "That is the correct answer, go again? (y/n)"; Q3Res++; state = SEVENTHstate; } else { theOutput = " WRONG!! TRY AGAIN"; state = SIXTHstate; } TOTALRes = Q1Res; theOutput = ("you got")+clues[Q1Res+Q2Res]; //--------------- } else if (state == SEVENTHstate) { if (theInput.equalsIgnoreCase("y")) { theOutput = "Q1: (A + B)*(A+B)" + " 1.A*A+B*B "+ " 2.A*A+A*B+B*B " + " 3.A*A+2*A*B+B*B "; if (currentQues == (NUMques - 1)) currentQues = 0; else currentQues++; state = SECONDstate; } else { theOutput = "Bye."; state = FIRSTstate; } } return theOutput; } }