Guest User

Mini-assignment 1

a guest
Dec 28th, 2013
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Part 1
  2.  
  3.     require 'date'
  4.  
  5.     #This function tells you how many hours are in a year
  6.     def hoursinyear
  7.         hours = 24*365
  8.         return 'There are ' + hours.to_s + ' hours in one year'
  9.     end
  10.  
  11.      #This function tells you how many minutes are in a decade
  12.     def minutesindeacde
  13.         minutes = 60*24*365*10
  14.         return 'There are ' + minutes.to_s + ' minutes in one decade'
  15.     end
  16.  
  17.     #This function gets a users age and then converts their age into seconds
  18.     def ageinseconds
  19.         puts 'Please enter your age in years:'
  20.         STDOUT.flush
  21.         age = gets.chomp.to_i
  22.         today = Date.today.to_time.to_i
  23.         seconds = age*24*3600*365 + today
  24.         return 'You are ' + seconds.to_s + ' seconds old'
  25.     end
  26.  
  27.     #This function calculates how many chocolates you hope to eat in your life (assumes lifespan of 80 years)
  28.     def chocolates
  29.         puts 'Pleae enter how many chocolates, on average, you eat a week?'
  30.         STDOUT.flush
  31.         chocolate = gets.chomp.to_i
  32.         totalcandy = chocolate*52*80
  33.         return 'You will eat ' + totalcandy.to_s + ' chocolates in your life'
  34.     end
  35.  
  36.     #Print responses
  37.     puts hoursinyear
  38.     puts minutesindeacde
  39.     puts ageinseconds
  40.     puts chocolates
  41.  
  42. Part 2
  43.  
  44.     #This function greets the user with their name
  45.     def username
  46.         puts 'Please enter your first name:'
  47.         STDOUT.flush
  48.         firstname = gets.chomp
  49.         puts 'Please enter your middle name:'
  50.         STDOUT.flush
  51.         middlename = gets.chomp
  52.         puts 'Please enter your last name:'
  53.         STDOUT.flush
  54.         lastname = gets.chomp
  55.         return 'Your full name is ' + firstname + ' ' + middlename + ' ' + lastname + '. Nice to meet you!'
  56.     end
  57.  
  58.     #Favorite number function
  59.     def favnumber
  60.         puts 'Please enter your favorite number:'
  61.         STDOUT.flush
  62.         number = gets.chomp.to_i
  63.         return 'Although ' + number.to_s + ' is a pretty good number. I think you may like ' + (number+1).to_s + ' more since it is harder, better, faster, and stronger (as a number of coarse!)'
  64.     end
  65.  
  66.     puts username
  67.     puts favnumber
  68.  
  69. Part 3
  70.  
  71.     def angryboss
  72.         puts 'Measly employee, what do you want!'
  73.         STDOUT.flush
  74.         res = gets.chomp
  75.         return 'WHADDAYA MEAN "' + res + '"?!? YOUR"RE FIRED!!'
  76.     end
  77.  
  78.     puts angryboss
Advertisement
Add Comment
Please, Sign In to add comment