Skip to content

Instantly share code, notes, and snippets.

@efecarranza
Created January 21, 2015 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efecarranza/264d9f33c324a1b2a7ba to your computer and use it in GitHub Desktop.
Save efecarranza/264d9f33c324a1b2a7ba to your computer and use it in GitHub Desktop.
Wyncode Methods 2
# Author: piscu Carranza
# January 19, 2015
# Week Two - Wyncode
# Profile
module WyncodeMethods
# Problems With Floats
puts "Here's a calculator to give the check with tip included."
class TipCalculator
def initialize(check, total=0)
@check = check
@total = total
end
def addTipToTotal
@total += (@check * 100 * 1.21)
@total = @total.to_i
return @total
end
def backToDecimal
return @total / 100.0
end
end
# calculator = TipCalculator.new(33.50)
# puts calculator.addTipToTotal
# puts calculator.backToDecimal
# # Christmas Tree
# # Program to Print christmas tree by looping rather than typing
class TreeMaker
def initialize(sym)
@sym = sym
end
def print_tree
num_star = 1
4.downto(1).each do |num_spaces|
print(' ' * num_spaces)
puts (@sym * num_star)
num_star += 2
end
end
end
# puts "Loop to create a christmas tree based on the character selected."
# puts "Please select any character to display a tree."
# response = gets.chomp
# tree = TreeMaker.new(response)
# tree.print_tree
end
require './wyncode_methods2.rb'
include WyncodeMethods
calculator = TipCalculator.new(33.50)
puts calculator.addTipToTotal
puts calculator.backToDecimal
# Tree Test
response = gets.chomp
tree = TreeMaker.new(response)
tree.print_tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment