D
Dwight Shackelford
First off, I'm a student taking Ruby for the first time, so bear with
me. I've tried doing a web search and a search of this forum, and
didn't see anything that addressed this specifically.
on line 18 of the following code (@height = @height * 1.1 in the method
oneYearPasses), I get the error message that is in the subject line.
If I take that same line of code and put it up in the area where I'm
defining variables, there is no error. I'm suspecting something has
gone amiss in my method definition and the interpreter is getting
confused.
If I comment out that line, I get similar messages for my '>' operators
below that.
Probably a bump from you folks on that first problem will give me enough
info to solve the others as they come up. Any help appreciated.
Thanks.
class OrangeTree
@numFruit =0
MAXAGE = 10
FIRSTFRUIT = 20
FIRSTHEIGHT = 3.0
@age = 0
@dead = false
@height = FIRSTHEIGHT
def getHeight
return @height
end
def oneYearPasses
if !@dead
@height = @height * 1.1 #<<<<<<<<<<<< line causing error
@age++
if @age >= 3
@numFruit = (1.2**(age -3)) * FIRSTFRUIT
end
if !(@age < MAXAGE)
@dead = true
end
end
end
def countTheOranges
return @numFruit
end
def pickAnOrange
if @numFruit > 0
@numFruit--
puts {'That was delicious'}
else
puts {'There are no more oranges'}
end
end
end
myTree = OrangeTree.new
myTree.oneYearPasses
myTree.oneYearPasses
myTree.pickAnOrange
myTree.getHeight
me. I've tried doing a web search and a search of this forum, and
didn't see anything that addressed this specifically.
on line 18 of the following code (@height = @height * 1.1 in the method
oneYearPasses), I get the error message that is in the subject line.
If I take that same line of code and put it up in the area where I'm
defining variables, there is no error. I'm suspecting something has
gone amiss in my method definition and the interpreter is getting
confused.
If I comment out that line, I get similar messages for my '>' operators
below that.
Probably a bump from you folks on that first problem will give me enough
info to solve the others as they come up. Any help appreciated.
Thanks.
class OrangeTree
@numFruit =0
MAXAGE = 10
FIRSTFRUIT = 20
FIRSTHEIGHT = 3.0
@age = 0
@dead = false
@height = FIRSTHEIGHT
def getHeight
return @height
end
def oneYearPasses
if !@dead
@height = @height * 1.1 #<<<<<<<<<<<< line causing error
@age++
if @age >= 3
@numFruit = (1.2**(age -3)) * FIRSTFRUIT
end
if !(@age < MAXAGE)
@dead = true
end
end
end
def countTheOranges
return @numFruit
end
def pickAnOrange
if @numFruit > 0
@numFruit--
puts {'That was delicious'}
else
puts {'There are no more oranges'}
end
end
end
myTree = OrangeTree.new
myTree.oneYearPasses
myTree.oneYearPasses
myTree.pickAnOrange
myTree.getHeight