Last active
January 5, 2016 22:22
-
-
Save darinthompson/e687427b5a19f811be11 to your computer and use it in GitHub Desktop.
temp converter
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
class Temperature | |
attr_accessor :temperature, :scale | |
def initialize(temperature = nil, scale = nil) | |
@temperature = temperature | |
@scale = scale | |
get_temperature | |
end | |
def get_temperature | |
if @temperature.nil? | |
puts "Temperature to be converted..." | |
@temperature = gets.chomp.to_i | |
puts "To Celcicus or to Farenheit (c/f)" | |
scale = gets.chomp.downcase | |
if scale == "f" | |
to_fahrenheit | |
else | |
to_celsius | |
end | |
else | |
if scale == "f" | |
to_fahrenheit | |
else | |
to_celsius | |
end | |
end | |
end | |
def to_fahrenheit | |
fahrenheit = (@temperature * (9.0/5.0)) + 32 | |
puts fahrenheit | |
end | |
def to_celsius | |
celsius = (@temperature - 32) * (5.0/9.0) | |
puts celsius | |
end | |
end | |
temp1 = Temperature.new(20, "f") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment