Created
January 21, 2015 01:48
-
-
Save efecarranza/264d9f33c324a1b2a7ba to your computer and use it in GitHub Desktop.
Wyncode Methods 2
This file contains 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
# 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 |
This file contains 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
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