Created
June 27, 2009 04:03
-
-
Save honorelsu/136889 to your computer and use it in GitHub Desktop.
Orange Tree
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 OrangeTree | |
def initialize tree | |
@age = tree | |
@orangecount = 0 | |
@height = 4 | |
end | |
def pickAnOrange | |
if @orangecount > 0 | |
@orangecount = @orangecount - 1 | |
puts 'My My, that was a delicious orange!' | |
else | |
puts 'Your tree has no oranges to bear. :-(' | |
end | |
end | |
def countTheOranges | |
puts 'Your tree contains ' + @orangecount.to_s + ' beautiful oranges.' | |
end | |
def treeheight | |
puts 'Your tree is ' + @height.to_s + ' feet tall.' | |
end | |
def oneYearPasses | |
@age = @age.to_i + 1 | |
@height = @height.to_f + 0.75 | |
puts 'Your tree is ' + @age.to_s + ' years old.' | |
if @age > 0 and @age < 4 | |
@orangecount = 0 | |
else | |
if @age >= 4 and @age < 50 | |
@orangecount = @orangecount.to_i + 8 | |
else | |
puts 'Your orange tree has gone to a better place. Plant a new tree.' | |
exit | |
end | |
end | |
end | |
end | |
num = 0 | |
orange = OrangeTree.new 0 | |
while num < 50 | |
orange.oneYearPasses | |
orange.treeheight | |
orange.countTheOranges | |
orange.pickAnOrange | |
puts '' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment