-
Notifications
You must be signed in to change notification settings - Fork 1
/
09_orangeTree.rb
81 lines (74 loc) · 1.56 KB
/
09_orangeTree.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class OrangeTree
def initialize
@age = 0
@height = 1
@fruits = 0
@alive = true
@fertile = false
puts 'You planted an Orange Tree.'
end
def height
puts 'Your tree is getting bigger and bigger, it\'s already ' + @height.to_s + ' meter tall.'
end
def countFruits
puts 'Wow, you already got ' + @fruits.to_s + ' piece of orange.'
end
def pickFruits
if @fruits > 1
@fruits = @fruits - 1
puts 'Whoops, who took away the orange? You only got ' + @fruits.to_s + ' left.'
else @fruits == 0
# @fruits is still 1, which is ok for the oneYearPasses, but didnt work for the countFruit
puts 'There is no more orange left you could eat.'
end
end
def oneYearPasses
@age = @age + 1
@height = @height + 1
if @age == 3
@fertile = true
@fruits = @fruits +2
end
if @age > 3
@fruits = @fruits * 2
end
puts 'Hooray, it\'s your tree\'s ' + @age.to_s + '. birthday!'
#end
if @age > 14
puts 'Your tree passed away after a life full of joy.'
@alive = false
@fertile = false
#@age = 0
end
end
end
#some thing's to try
tree = OrangeTree.new
tree.oneYearPasses
tree.oneYearPasses
tree.oneYearPasses
tree.countFruits
tree.oneYearPasses
tree.countFruits
tree.height
tree.pickFruits
tree.pickFruits
tree.pickFruits
tree.pickFruits
tree.pickFruits
tree.pickFruits
tree.oneYearPasses
tree.oneYearPasses
tree.countFruits
tree.pickFruits
tree.oneYearPasses
tree.countFruits
tree.height
tree.oneYearPasses
tree.oneYearPasses
tree.oneYearPasses
tree.oneYearPasses
tree.oneYearPasses
tree.oneYearPasses
tree.oneYearPasses
tree.oneYearPasses