Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rather than using a pass/fail grading system, modify the game to assign grades of A, B, C, D, and F to the player using a

Rather than using a pass/fail grading system, modify the game to assign grades of A, B, C, D, and F to the player using a 10-point grading scale. Make sure you use the case statement when implementing your solution.

#-------------------------------------------------------------------------- # # Script Name: TypingChallenge.rb # Version: 1.0 # Author: Jerry Lee Ford, Jr. # Date: March 2010 # # Description: This Ruby script demonstrates how to apply conditional logic # in order to analyze user input and control script execution # through the development of a computer typing test that # evaluates the player's typing skills. # #--------------------------------------------------------------------------

# Define custom classes ---------------------------------------------------

#Define a class representing the console window class Screen

def cls #Define a method that clears the display area puts (" " * 25) #Scroll the screen 25 times puts "\a" #Make a little noise to get the player's attention end def pause #Define a method that pauses the display area STDIN.gets #Execute the STDIN class's gets method to pause script #execution until the player presses the Enter key end end

#Define a class representing the typing test class Test

#This method displays the 8-ball greeting message def display_greeting Console_Screen.cls #Clear the display area #Display a welcome screen print "\t\t Welcome to the Ruby Typing Challenge game!" + " Press Enter to " + "continue. : " Console_Screen.pause #Pause the game

end

#Define a method to be used to present test instructions def display_instructions Console_Screen.cls #Clear the display area puts "\t\t\tInstructions: " #Display a heading

#Display the game's instructions puts %Q{ This test consists of a series of 5 typing challenges. The challenge sentences are presented one at a time. To respond correctly, you must retype each sentence exactly as shown and press the Enter key. Your grade will be displayed at the end of the test. Press Enter to continue. }

Console_Screen.pause #Pause the game end

#Define a method to be used to present typing challenges def present_test(challenge) Console_Screen.cls #Clear the display area print challenge + " : " #Display the challenge sentence result = STDIN.gets #Collect the player's input result.chop! #Remove the end of line marker #Analyze the player input and see if it is correct if challenge == result then #Keep track of the number of correctly retyped challenge sentences $noRight += 1 Console_Screen.cls #Clear the display area #Keep the player informed print "Correct! Press Enter to continue." Console_Screen.pause #Pause the game else Console_Screen.cls #Clear the display area #Keep the player informed print "Incorrect! Press Enter to continue." Console_Screen.pause #Clear the game end end

#Define a method to be used to display test results def determine_grade Console_Screen.cls #Clear the display area #To pass the test the player must correctly retype 3 sentences if $noRight >= 3 then #Inform the player of the good news print "You retyped " + $noRight.to_s + " sentence(s) correctly. " puts "You have passed the typing test! Press Enter to continue." else #The player has failed the test #Inform the player of the bad news print "You retyped " + $noRight.to_s + " sentence(s) correctly. " puts "You have failed the typing test! Press Enter to continue." end end

end

# Main Script Logic -------------------------------------------------------

#Initialize global variable that will be used to keep track of the number #of correctly retyped sentences $noRight = 0

Console_Screen = Screen.new #Instantiate a new Screen object Typing_Test = Test.new #Instantiate a new Test object

#Execute the Test object's display_greeting method Typing_Test.display_greeting

#Execute the Screen object's cls method in order to clear the screen Console_Screen.cls

#Prompt the player for permission to begin the test print "Would you like to test your typing skills? (y/n) : "

answer = STDIN.gets #Collect the player's response answer.chop! #Remove any extra characters appended to the string #Loop until the player enters y or n and do not accept any other input. until answer == "y" || answer == "n"

Console_Screen.cls #Clear the display area

#Prompt the player for permission to begin the test

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions