Created
June 18, 2012 14:29
-
-
Save seldomatt/2948644 to your computer and use it in GitHub Desktop.
Jukebox Assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a file jukebox.rb | |
# When that program is run, it should introduce itself | |
# to the user and accept input from the user using the gets command. | |
# The jukebox should respond to 3 commands, help, play, list and exit. | |
# The help command should output instructions for the user | |
# on how to use the jukebox. | |
# The list command should output a list of songs that the | |
# user can play. | |
# the play command should accept a song, either by number/index | |
# or name. Once the user has indicated which song they want to | |
# play, the jukebox should output 'Playing The Phoenix - 1901' | |
# or whatever song name is important. | |
# if the user types in exit, the jukebox should say goodbye | |
# and the program should shut down. | |
# Think about the following things | |
# How to keep the program running until the exit command is | |
# executed (Hint: Loop maybe? Loop upon a condition) | |
# How to normalize the user's input so LIST and list are the | |
# same. (Hint, maybe downcase and strip it) | |
# How to give the songs an "index" so that when you list them | |
# out, you can refer to them by position so the user can just | |
# type play 1 and then you find the first song. (Hint, check | |
# out a method called each_with_index) | |
songs = [ | |
"The Phoenix - 1901", | |
"Tokyo Police Club - Wait Up", | |
"Sufjan Stevens - Too Much", | |
"The Naked and the Famous - Young Blood", | |
"(Far From) Home - Tiga", | |
"The Cults - Abducted", | |
"The Phoenix - Consolation Prizes" | |
] | |
songs.sort! | |
helplang = "To learn how to use this jukebox, type 'help'. | |
To see a list of all the songs this jukebox can play, type 'list'. To play a song, type 'play' and then the song name or it's correspondeing number. | |
To see these directions at any time, type 'help'. | |
To exit jukebox at anytime, type 'exit'. Enjoy the tunes!" | |
puts "Hi, this is your fancy new jukebox! What's your name?" | |
name = gets | |
puts "Hi #{name.capitalize.chomp}! #{helplang}" | |
command = gets | |
while command != "exit" | |
case command.downcase.strip | |
when "list" | |
songs.each_with_index do |songname, i| | |
puts "Type #{i+1} to hear #{songname}." | |
end | |
puts "Which song do you want to play?" | |
command = gets | |
# # case command.downcase.strip | |
# # when "play #{songs[i+1]}" | |
# # puts "Now playing #{songs[i]}" | |
# # command = gets | |
# # when "play #{songs[]}" | |
# # puts "Now playing #{songs[]}" | |
# # command = gets | |
# # else | |
# # puts "That is not a valid command in jukebox" | |
# # command = gets | |
# # end | |
# # end | |
# when "play #{songs[i+1]}" || "play #{songname}" | |
# puts "Now playing #{songname}." | |
# command = gets | |
# when "play " + number | |
# songs.each_with_index do |songname, i| | |
# puts "Now playing #{songs[number - 1]}" | |
# command = gets | |
when "help" | |
puts helplang | |
command = gets | |
when "exit" | |
puts "Goodbye #{name.capitalize.chomp}!" | |
break | |
else | |
puts "That is not a valid command in jukebox" | |
command = gets | |
end | |
end | |
#while input != exit - this is the way to keep the program running, setup a program that has a loop until you type in exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment