Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment #1.1: Ruby Joke Summary: Complete the Ruby Joke program. The solution file should be named RubyJoke_ExerciseE.rb. Use the instructions starting on page 38 of

Assignment #1.1: Ruby Joke

Summary: Complete the Ruby Joke program.

The solution file should be named RubyJoke_ExerciseE.rb.

Use the instructions starting on page 38 of the textbook.

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

Add the necessary documentation as described in Course Documents, and then attach your .rb file to this assignment

#-------------------------------------------------------------------------- # # Script Name: RubyJoke.rb # Version: 1.0 # Author: Jerry Lee Ford, Jr. # Date: March 2010 # # Description: This Ruby script tells a series of 5 humorous jokes # #--------------------------------------------------------------------------

# 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 end end

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

Console_Screen = Screen.new #Initialize a new Screen object

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

#Prompt the player for permission to begin the game puts "Would you like to hear a few funny jokes? (y/n)"

#Collect the player's response answer = STDIN.gets

#Remove any extra characters appended to the string answer.chop!

#Analyze the player's response if answer == "n" #See if the player elected not to play

Console_Screen.cls #Clear the display area

#Invite the player to return and play again puts "Sorry to hear that. Please return and play again soon."

else Console_Screen.cls #Clear the display area

#Display the beginning of the first joke puts "What is black and white and red all over? (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

#Display the punch line puts "A messy penguin eating cherry pie! (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

Console_Screen.cls #Clear the display area #Display the beginning of the second joke puts "What is black and white and red all over? (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

#Display the punch line puts "A sunburned penguin! (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

Console_Screen.cls #Clear the display area #Display the beginning of the third joke puts "What is black and white and red all over? (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

#Display the punch line puts "An embarrassed Dalmatian puppy! (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

Console_Screen.cls #Clear the display area #Display the beginning of the fourth joke puts "What is black and white and red all over? (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

#Display the punch line puts "A zebra with a scratched knee! (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

Console_Screen.cls #Clear the display area #Display the beginning of the fifth joke puts "What is black and white and red all over? (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

#Display the punch line puts "A skunk with diaper rash! (Press Enter)"

pause = STDIN.gets #Force the player to press Enter to continue

Console_Screen.cls #Clear the display area

puts "Thanks for playing the Ruby Joke game!"

end

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Have roles been defined and assigned?

Answered: 1 week ago

Question

Are these written ground rules?

Answered: 1 week ago