Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment #4: Superman Quiz Summary: Create the Superman Quiz program. The solu

ID: 3849420 • Letter: A

Question

Assignment #4: Superman Quiz

Summary: Create the Superman Quiz program.

The solution file should be named SupermanQuiz_ExerciseE.rb.

Use the instructions on page 178 of the textbook.

Run your program until it works and the output looks nice.

Reinforcement Exercises The following exercises are designed to further your understanding of Ruby programming by challenging you to make improvements to the chapters game project, the Superman Movie Trivia Quiz 1. Currently, the Superman Movie Trivia Quiz consists offive questions. Make the quiz more challenging by increasing its size to 10 questions. To implement this change, copy the last of the five statements that call on the Quiz object's disp q method to pose a quiz question. Add five copies of the statement immediately after the copied statement's question along with the corresponding answers You will also have to adjust the way the method calculates the number of questions missed. To do so, modify the determine grade method so that six or more questions must be correctly answered to pass the quiz 2. Give players the opportunity to take the quiz again if they fai 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. 3. Modify the quiz so that if the player decides not to take the quiz, the game still displays the text displayed by the display credits method. To implement this change, replace the statements at the end of the program file that invite the player to play again with a statement that executes the Quiz object's display credits method.

Explanation / Answer

Hello,

Since I was not provided with Quiz questions, I am providing a dummy questions generator, which you can replace by providing questions of your own. The methods "display_credits" and "determine_grade" might also be different for the same reasons:

# A Question class, consisting of a Question, its Options, and a number detrmining which
# is the rightAnswer
class Question
#all_Questions contains an array of all questions created so far
@@all_Questions = Array.new

def initialize(question, option1, option2, option3, option4, rightAnswer)
    @question=question
    @option1=option1
    @option2=option2
    @option3=option3
    @option4=option4
    @rightAnswer=rightAnswer
    @@all_Questions << self
end

def display_question()
    puts @question
    puts "1. #@option1"
    puts "2. #@option2"
    puts "3. #@option3"
    puts "4. #@option4"
end

def self.getAllQuestions
    @@all_Questions
end

def getRightAnswer
    @rightAnswer
end

end

#Since questions were not provided, I am adding
#A dummy quiz prepartion function, you can add real questions if you like
def prepareQuestions
    questionSet = []
    for i in (1..10)
    Question.new("Dummy Question","Option1","Option2","Option3","Option4",2)
    end
end

#Change it according to the assignment
def display_credits
    print "Made by Me!! Thank you for playing "
end

#Returns wheter Passed or Failed
def determine_grade(score)
result=""

if score < 6
    result="Fail"
else result = "Pass"
end
return result
end


#This is the main part, where most of the action happens
def play
    score=0
  
    prepareQuestions
  
    print "playing.. "
  
    for question in Question.getAllQuestions
      question.display_question
      print " Enter your choice"
      option = gets.chomp.to_i
    
      if option == question.getRightAnswer
        score+=1
        puts "Correct Answer"
      else
        puts "Wrong Answer"
      end
      puts "Your Current score is #{score}"
      print " "
    end
  
    print " Your Final Score is : #{score} "
    return determine_grade(score)
end

print "====The SuperMan Movie Quiz==== "

choice=""

#will loop over, until an exit is recieved
while(choice!="exit")
print " Type play to Play "
print "Or Type exit to Exit "
choice = gets.chomp
if choice =='exit'
    display_credits
else
    result=play
    puts result
  
    if result == "Fail"
      puts "Hey! Dont worry, you can retake the quiz to improve your score"
    end
end  
end