Ruby problem.
Here is the problem:
Here is “program file in Step 10” the problem isreferring to:
Here is the code (please help me solve the problemin picture above):
—————————————————————————-
2. Give players the opportunity to take the quiz again if they fail. To implement this change, add the appropriate statements in a loop within the script’s Main Script Logic section (added to the program file in Step 10). Prompt the player to take the quiz again if fewer than six questions are answered correctly. If the player elects not to retake the quiz, terminate the execution of the loop and allow the quiz to end. Step 10: Instantiate Script Objects Instantiate two objects named Console_Screen and SQ, based on the Console_Screen and Quiz classes, by adding the following statements to the end of the script file: # Main Script Logic —- #Initialize global variable that will be used to keep #track of the number of correctly answered quiz #questions $noRight = 0 Console_Screen – Screen.new #Instantiate a new Screen #object SQ = Quiz.new #Instantiate a new Quiz object #Execute the Quiz class’s display_greeting method SQ.display_greeting In addition to instantiating the Console_Screen and SQ objects, these statements define a global variable named SnoRight, which is used both to keep track of the number of correctly answered questions and to execute the Quiz class’s display_greeting method. We were unable to transcribe this imageConsole_Screen.pause #Pause the game end #Define a method to be used to present quiz instructions def display_instructions Console_Screen.cls puts “INSTRUCTIONS:nn” #Clear the display area #Display a heading, #Display the game’s instructions puts “You will be presented with a series of multiple-choice” puts “questions. To answer a question, type in the letter of” puts “the corresponding answer and press the Enter key. Your” puts “grade will be displayed at the end of the test. Innn”, puts “Good luck!nnnnnnnnn” print “Press Enter to continue.” Console_Screen.pause #Pause the game end #Define a method to be used to present and process quiz questions def disp_9(question, qua, q_B, q_C, q_D, answer) #Loop until the player inputs a valid answer loop do Console_Screen.cls #Clear the display area #Format the display of the quiz question #Format the display of the quiz question puts question + “nn” puts q_A puts q_B puts q_C puts q_D print “nType the letter representing your answer: ” reply = STDIN.gets #Collect the player’s answer reply.chop! #Remove the end of line marker #Analyze the player’s input to determine if it is correct if answer == reply then #Keep track of the number of correctly answered questions $noRight += 1 end #Analyze the answer to determine if it was valid if reply == “a” or reply == “b” or reply == “C” or reply == “d” then break #Terminate the execution of the loop end end 100 101 102 103 104 105 106 107 end #Define a method to be used to grade and display quiz results def determine_grade We were unable to transcribe this image144 def display_credits 139 140 Console_Screen.cls #clear the display area 141 142 #Thank the player and display game information 143 puts “ttThank you for taking the SUPERMAN MOVIE TRIVIA QUIZ.nnnn”, puts “nttt Developed by Jerry Lee Ford, Jr. Inn” 145 puts “tttt Copyright 2010nn” 146 puts “tttURL: http://www.tech-publishing.comnnnnnnnnnn” 147 148 end 149 150 end 151 152 153 # Main Script Logic — 154 155 #Initialize global variable that will be used to keep track of the number #of correctly answered quiz questions 157 $noRight = 0 158 159 Console Screen = Screen.new #Instantiate a new Screen object 160 SQ = Quiz.new #Instantiate a new Quiz object 161 162 #Execute the Quiz class’s display greeting method 163 SQ.display_greeting 164 165 answer = “” 166 167 #Loop until the player enters y or n and do not accept any other input. 168 v loop do 156 #Loop until the player enters y or n and do not accept any other input. loop do Console_Screen.cls #clear the display area #Prompt the player for permission to start the quiz print “Are you ready to take the quiz? (y/n): ” 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 answer = STDIN.gets #Collect the player’s response answer.chop! #Remove one character from the end of the string break if answer == “y” || answer == “n”, end #Analyze the player’s input if answer == “n” #See if the player elected not to take the quiz Console_Screen.cls #clear the display area 187 #Invite the player to return and take the quiz some other time puts “Okay, perhaps another time. Inn”, 188 189 190 191 else #The player wants to take the quiz 192 #Execute the Quiz class’s display_instructions method SQ.display_instructions 193 194 195 196 197 #Execute the Quiz class’s disp_g method and pass it #arguments representing a question, possible answers and the letter #of the correct answer #arguments representing a question, possible answers and the letter #of the correct answer SQ.disp_a(“What is the name of the Daily Planet’s ace photographer?”, “a. Jimmy Olsen”, “b. Clark Kent”, “C. Lex Luthor”, “d. Lois Lane”, “a”) #Call upon the disp_q method and pass it the second question SQ.disp_q(“What is the name of Clark Kent’s home town?”, “a. Metropolis”, “b. Gotham City”, “C. Smallville”, “d. New York”, “c”) #Call upon the disp_q method and pass it the third question SQ.disp_q(“In which movie did Superman battle General Zod?”, “a. Superman”, “b. Superman II”, “c. Superman III”, “d. Superman IV”, “b”) #Call upon the disp_q method and pass it the fourth question SQ.disp_9(“What is the name of Superman’s father?”, “a. Nimo”, “b. Jarrell”, “c. Lex Luthor”, “d. Krypton”, “b”) #Call upon the disp_q method and pass it the fifth question SQ.disp_9(“Where had Superman been at the start of ‘Superman Returns’?”, “a. Moon”, “b. Fortress of Solitude”, “C. Earth’s Core”, “d. Krypton”, “d”) 220 221 222 223 v 224 225 #Call upon the disp_q method and pass it the sixth question SQ.dispa(“How many basic colors of Kryptonite are there?”, “a. Two”, “b. Three”, “C. Four”, “d. Five”, “b”) #Call upon the disp_q method and pass it the seventh question 227 228 v 229 #Call upon the disp_q method and pass it the seventh question so.disp_g(“What is the object Superman is holding on the cover of his comics?”, “a. Donald Trump”, “b. A stale twinkie”, “C. A car”, “d. A boombox”, “c”) 231 232 233 V #Call upon the disp_q method and pass it the eighth question so.disp q “What color kryptonite causes weakness and is eventually fatal to natives of Krypton?”, “a. Yellow”, “b. Green”, “c. Blue”, “d. Superman is colorblind”, “b”) #Call upon the disp_q method and pass it the nineth question SQ.disp_9(“What is Superman’s birth name?”, “a. Nerd Boy”, “b. Justin Bieber”, “C. RuPaul”, “d. Kal-El”, “d”) 237 238 V 239 240 241 242 243 V 244 245 246 #Call upon the disp_q method and pass it the tenth question SQ.disp_9(“Who is Clark Kent married to?”, “a. Lois Lane”, “b. Cardi B”, “C. Andy Dick”, “d. Turtlez”, “a”) 247 248 #Call upon the Quiz class’s determine_grade method to display #the player’s grade and assigned rank SQ. determine_grade 249 250 251 252 #Call upon the Quiz class’s display_credits method to thank #the player for taking the quiz and to display game information SQ.display_credits 253 254 255 end Show transcribed image text 2. Give players the opportunity to take the quiz again if they fail. To implement this change, add the appropriate statements in a loop within the script’s Main Script Logic section (added to the program file in Step 10). Prompt the player to take the quiz again if fewer than six questions are answered correctly. If the player elects not to retake the quiz, terminate the execution of the loop and allow the quiz to end.
Step 10: Instantiate Script Objects Instantiate two objects named Console_Screen and SQ, based on the Console_Screen and Quiz classes, by adding the following statements to the end of the script file: # Main Script Logic —- #Initialize global variable that will be used to keep #track of the number of correctly answered quiz #questions $noRight = 0 Console_Screen – Screen.new #Instantiate a new Screen #object SQ = Quiz.new #Instantiate a new Quiz object #Execute the Quiz class’s display_greeting method SQ.display_greeting In addition to instantiating the Console_Screen and SQ objects, these statements define a global variable named SnoRight, which is used both to keep track of the number of correctly answered questions and to execute the Quiz class’s display_greeting method.
Console_Screen.pause #Pause the game end #Define a method to be used to present quiz instructions def display_instructions Console_Screen.cls puts “INSTRUCTIONS:nn” #Clear the display area #Display a heading, #Display the game’s instructions puts “You will be presented with a series of multiple-choice” puts “questions. To answer a question, type in the letter of” puts “the corresponding answer and press the Enter key. Your” puts “grade will be displayed at the end of the test. Innn”, puts “Good luck!nnnnnnnnn” print “Press Enter to continue.” Console_Screen.pause #Pause the game end #Define a method to be used to present and process quiz questions def disp_9(question, qua, q_B, q_C, q_D, answer) #Loop until the player inputs a valid answer loop do Console_Screen.cls #Clear the display area #Format the display of the quiz question
#Format the display of the quiz question puts question + “nn” puts q_A puts q_B puts q_C puts q_D print “nType the letter representing your answer: ” reply = STDIN.gets #Collect the player’s answer reply.chop! #Remove the end of line marker #Analyze the player’s input to determine if it is correct if answer == reply then #Keep track of the number of correctly answered questions $noRight += 1 end #Analyze the answer to determine if it was valid if reply == “a” or reply == “b” or reply == “C” or reply == “d” then break #Terminate the execution of the loop end end 100 101 102 103 104 105 106 107 end #Define a method to be used to grade and display quiz results def determine_grade
144 def display_credits 139 140 Console_Screen.cls #clear the display area 141 142 #Thank the player and display game information 143 puts “ttThank you for taking the SUPERMAN MOVIE TRIVIA QUIZ.nnnn”, puts “nttt Developed by Jerry Lee Ford, Jr. Inn” 145 puts “tttt Copyright 2010nn” 146 puts “tttURL: http://www.tech-publishing.comnnnnnnnnnn” 147 148 end 149 150 end 151 152 153 # Main Script Logic — 154 155 #Initialize global variable that will be used to keep track of the number #of correctly answered quiz questions 157 $noRight = 0 158 159 Console Screen = Screen.new #Instantiate a new Screen object 160 SQ = Quiz.new #Instantiate a new Quiz object 161 162 #Execute the Quiz class’s display greeting method 163 SQ.display_greeting 164 165 answer = “” 166 167 #Loop until the player enters y or n and do not accept any other input. 168 v loop do 156
#Loop until the player enters y or n and do not accept any other input. loop do Console_Screen.cls #clear the display area #Prompt the player for permission to start the quiz print “Are you ready to take the quiz? (y/n): ” 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 answer = STDIN.gets #Collect the player’s response answer.chop! #Remove one character from the end of the string break if answer == “y” || answer == “n”, end #Analyze the player’s input if answer == “n” #See if the player elected not to take the quiz Console_Screen.cls #clear the display area 187 #Invite the player to return and take the quiz some other time puts “Okay, perhaps another time. Inn”, 188 189 190 191 else #The player wants to take the quiz 192 #Execute the Quiz class’s display_instructions method SQ.display_instructions 193 194 195 196 197 #Execute the Quiz class’s disp_g method and pass it #arguments representing a question, possible answers and the letter #of the correct answer
#arguments representing a question, possible answers and the letter #of the correct answer SQ.disp_a(“What is the name of the Daily Planet’s ace photographer?”, “a. Jimmy Olsen”, “b. Clark Kent”, “C. Lex Luthor”, “d. Lois Lane”, “a”) #Call upon the disp_q method and pass it the second question SQ.disp_q(“What is the name of Clark Kent’s home town?”, “a. Metropolis”, “b. Gotham City”, “C. Smallville”, “d. New York”, “c”) #Call upon the disp_q method and pass it the third question SQ.disp_q(“In which movie did Superman battle General Zod?”, “a. Superman”, “b. Superman II”, “c. Superman III”, “d. Superman IV”, “b”) #Call upon the disp_q method and pass it the fourth question SQ.disp_9(“What is the name of Superman’s father?”, “a. Nimo”, “b. Jarrell”, “c. Lex Luthor”, “d. Krypton”, “b”) #Call upon the disp_q method and pass it the fifth question SQ.disp_9(“Where had Superman been at the start of ‘Superman Returns’?”, “a. Moon”, “b. Fortress of Solitude”, “C. Earth’s Core”, “d. Krypton”, “d”) 220 221 222 223 v 224 225 #Call upon the disp_q method and pass it the sixth question SQ.dispa(“How many basic colors of Kryptonite are there?”, “a. Two”, “b. Three”, “C. Four”, “d. Five”, “b”) #Call upon the disp_q method and pass it the seventh question
227 228 v 229 #Call upon the disp_q method and pass it the seventh question so.disp_g(“What is the object Superman is holding on the cover of his comics?”, “a. Donald Trump”, “b. A stale twinkie”, “C. A car”, “d. A boombox”, “c”) 231 232 233 V #Call upon the disp_q method and pass it the eighth question so.disp q “What color kryptonite causes weakness and is eventually fatal to natives of Krypton?”, “a. Yellow”, “b. Green”, “c. Blue”, “d. Superman is colorblind”, “b”) #Call upon the disp_q method and pass it the nineth question SQ.disp_9(“What is Superman’s birth name?”, “a. Nerd Boy”, “b. Justin Bieber”, “C. RuPaul”, “d. Kal-El”, “d”) 237 238 V 239 240 241 242 243 V 244 245 246 #Call upon the disp_q method and pass it the tenth question SQ.disp_9(“Who is Clark Kent married to?”, “a. Lois Lane”, “b. Cardi B”, “C. Andy Dick”, “d. Turtlez”, “a”) 247 248 #Call upon the Quiz class’s determine_grade method to display #the player’s grade and assigned rank SQ. determine_grade 249 250 251 252 #Call upon the Quiz class’s display_credits method to thank #the player for taking the quiz and to display game information SQ.display_credits 253 254 255 end
Expert Answer
Answer to Ruby problem. Here is the problem: Here is “program file in Step 10” the problem is referring to: Here is the code (plea…