java - Outputting users answers and the correct answers in the method "void quizResults()" -


class quizmethods {     string [] questions = new string [20];     string [] answers   = new string [20];     string [] correctanswers = new string [20];     int score;      void fillarrays() {             questions[0] = " lead guitarist of led zeppelin?";           correctanswers[0] = "jimmy page";          questions[1] = "who lead singer of led zeppelin?";          correctanswers[1]= "robert plant";          questions[2] = "who lead guitarist of pink floyd?";           correctanswers[2] = "david gilmour";          questions[3] = "who bassist , main lyricist of pink floyd?";          correctanswers[3]= "roger waters";          questions[4] = "under category of music pink floyd entitled too?";           correctanswers[4] = "soft rock";          questions[5] = "under category of music metallica entitled too?";          correctanswers[5]= "trash metal";          questions[6] = "who lead guitarist of metallica?";           correctanswers[6] = "kirk hammet";          questions[7] = "who lead singer , rhythm guitarist of metallica?";          correctanswers[7]= "james hetfield";          questions[8] = "who lead guitarist of guns n roses?";           correctanswers[8] = "slash";          questions[9] = "who lead singer of guns n roses?";          correctanswers[9]= "axl rose";          questions[13] = "under category of music guns n roses entitled too?";          correctanswers[13]= "hard rock";          questions[11] = "who bassist of guns n roses?";          correctanswers[11]= "duff mckagan";          questions[12] = "name biggest , sold album of pink floyd";           correctanswers[12] = "the wall";          questions[13] = "under category of music zz top entitled too?";          correctanswers[13]= "blues rock";          questions[14] = "who lead guitarist , vocalist of zz top?";           correctanswers[14] = "billy gibbons";          questions[15] = "who considered king of blues?";          correctanswers[15]= "bb king";          questions[16] = "who lead singer popular band queen?";           correctanswers[16] = "freddie mercury";          questions[17] = "who lead singer heavy metal band black sabbath?";          correctanswers[17]= "ozzy osbourne";          questions[18] = "who lead guitarist of dire straits?";           correctanswers[18] = "mark knopfler";          questions[19] = "complete sentence.alphaville released song named _______ _______ in september 1984.";          correctanswers[19]= "forever young";     }      void takequiz(){         string answer;         int i;         (i = 0; < 20; i++) {             system.out.print(questions[i] + "\nanswer: ");             answer = keyboard.readstring();             answers[i] = answer;              if (answer.equalsignorecase(correctanswers[i])) {                 score++;             } else {                 score--;             }         }     }      void quizresults() {     }      void performancecomment() {     }      void exit() {     }      void menu() {         system.out.println("1. take quiz");         system.out.println("2. quiz results");         system.out.println("3. performance comment");         system.out.println("4. exit");         system.out.print("choose above:");         byte menu = keyboard.readbyte();         switch(menu) {          case 1:              takequiz();             break;          case 2:             quizresults();             break;          case 3:             performancecomment();             break;          case 4:              exit();                 }     } } 

i output users answers , correct answers in method void quizresults(). don't know use this. how can end program in method void exit()?

you have stored user's answers , have correct answers in arrays. indexes should line up, can cycle through arrays , output screen.

something like:

public void quizresults(){     for(int = 0; i<20; i++){         system.out.println("question: #" + i);         system.out.println("you answered: " + answers[i]);         system.out.println("correct answer: " + correctanswers[i]); } 

i recommend put in default case switch statement. if user enters other 1,2,3 or 4, need handle in appropriate way (i.e. message stating entered invalid option.)


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -