Advertisement
Guest User

yo

a guest
Jul 26th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. movies = {
  2. Memento: 4,
  3. American_Beauty: 3,
  4. Inception: 5
  5. }
  6.  
  7. puts "Enter your choice!"
  8. puts "Type add to add a movie and it's rating."
  9. puts "Type update to update a movie rating."
  10. puts "Type display to show the movie and it's rating."
  11. puts "Type delete to remove a movie from the list."
  12. choice = gets.chomp
  13.  
  14. case choice
  15. when "add"
  16. puts "What is the title of the movie you want to add?"
  17. title = gets.chomp
  18. if movies[title.to_sym].nil?
  19. puts "How would you rate that movie?"
  20. rating = gets.chomp
  21. movies[title.to_sym] = rating.to_i
  22. puts "We have added #{title} with the rating of #{rating}!"
  23. else
  24. puts "We already have that movie in the system."
  25. puts "It's rating is #{rating}"
  26. end
  27. when "update"
  28. puts "What is the title of the movie you want to update?"
  29. title = gets.chomp
  30. if movies[title.to_sym].nil?
  31. puts "Error!"
  32. else
  33. puts "How would you rate the movie?"
  34. rating = gets.chomp
  35. movies[title.to_sym] = rating.to_i
  36. puts "We have updated #{title} with the rating of #{rating}!"
  37. end
  38. when "display"
  39. movies. each do |movie, rating|
  40. puts "#{movie}: #{rating}"
  41. end
  42. when "delete"
  43. puts "What is the title of the movie you want to delete?"
  44. title = gets.chomp
  45. if movies[title.to_sym].nil?
  46. puts "Error!"
  47. else
  48. movies.delete(title.to_sym)
  49. puts "We have deleted #{title} from the list."
  50. end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement