Created
March 27, 2012 02:48
-
-
Save solomon081/2212057 to your computer and use it in GitHub Desktop.
Shape Class
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 Shape | |
def initialize(sides, perimiter, name) | |
@name = name | |
@sides = sides | |
@perimiter = perimiter | |
puts "Shape Name: #@name" | |
puts "Sides: #@sides" | |
puts "Perimiter: #@perimiter" | |
puts "Avg. Side Length: " + (@perimiter.to_i/@sides.to_i).to_s | |
if @sides.to_i < 3 or @perimiter.to_i <= 0 | |
puts "This shape is impossible!" | |
end | |
end | |
end | |
pentagon = Shape.new('5', '30', "Pentagon One") | |
square = Shape.new('4', '50', "Shape One") | |
invalid = Shape.new('2', '3', "Invalid Shape") | |
invalid2 = Shape.new("4", '-1', "Invalid Two") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment