Created
January 21, 2015 22:22
-
-
Save troyleach/dd448276ddf149724a4c to your computer and use it in GitHub Desktop.
screencast 17
This file contains hidden or 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
| #screen cast 17 | |
| class Calculator | |
| include Math | |
| def add(num1, num2) | |
| num1 + num2 | |
| end | |
| def multiply(num1, num2) | |
| num1 * num2 | |
| end | |
| def divide(num1, num2) | |
| num1 / num2 | |
| end | |
| def subtract(num1, num2) | |
| num1 - num2 | |
| end | |
| def circumference_of_a_circle(radius) | |
| @c = 2 * PI * radius | |
| end | |
| def what_is_the_radus(input) | |
| circumference_of_a_circle(input) | |
| end | |
| def display_answer | |
| "The circumference of the circle is #{@c.round(3)}" | |
| end | |
| end | |
| calc = Calculator.new | |
| p calc.add(2, 4) | |
| p calc.multiply(4, 4) | |
| p calc.divide(10, 5) | |
| p calc.subtract(50, 100) | |
| print "Enter a radius: " | |
| calc.what_is_the_radus(gets.chomp.to_i) | |
| p calc.display_answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I love the circumference method - I think you're the first to come up with that!