Okay so I have created the code, when i try to run the script in Eclipse i got this error uninitialized constant DrvierExam::Console_Screen (NameError) . senerio for creating the script is students have to take 20 question, which they will have to get 75% to pass which is 15 question. class name needs to have to have array which correct answer for question and array that collects students answers.
I think i am on the write track with creating both arrays, but not sure, and getting the error at beginning.
$ class Screen
def cls
puts ("\n" * 10)
puts "\a"
end
def pause
end
end
class DrvierExam
def display_greeting # This is a method
Console_Screen.cls #Clears the Screen
print "\t\t Welcome To Georgia Department Driver Services" + "\n\nPress Enter to Continue"
Console_Screen.pause
end
def display_instructions
Console_Screen.cls
puts "INSTRUCTIONS:\n\n"
puts "You are starting DMV exam for your drivers licence"
puts "You will be presented with multiple choice question,"
puts "Please type the letter of the correct choice"
puts "Grades will be shown at the end"
puts "Good Luck For the First Licence"
print "Press Enter to Continue"
Console_Screen.pause
end
def CorrectAnswer
test = %w[1B 2D 3A 4A 5C 6B 7B 8A 9C 10D 11B 12C 13D 14D 15D 16C 17C 18B 19D 20A] #Array for real anwer
end
def disp_q(question, q_A, q_B, q_C, q_D, answer)
loop do
Console_Screen.cls
puts question + "\n\n"
puts q_A
puts q_B
puts q_C
puts q_D
print "Type the letter representing your answer: "
answer = []
reply =开发者_Python百科 STDIN.gets
reply.chop!
if answer == reply then
$noRight +=1
end
if reply == "a" or reply == "b" or reply == "c" or reply == "d" then
break
end
end
end
You're referring to your "Screen" class as "Console_Screen". Change all references to Screen, and it should work fine.
精彩评论