Beta

Pine's Orange Tree

Description:

Orange Tree

Make an OrangeTree class that has a height method that returns its height and a one_year_passes method that, when called, ages the tree one year.

Each year the tree grows 0.4 meters taller, and after 25 years the tree should die.

For the first 5 years, it should not produce fruit, but in its sixth year it should, and older trees produce more each year than younger trees... (at a rate of height * 15 - 25 per year)

And, of course, you should be able to count_the_oranges (which returns the number of oranges on the tree) and pick_an_orange (which reduces the @orange_count by 1 and returns a string telling you how delicious the orange was, or else it just tells you that there are no more oranges to pick this year).

Make sure any oranges you don’t pick one year fall off before the next year.

####******* In order to pass test cases, follow the below rates of growth, orange production and age of death:

  • The OrangeTree grows by 0.4 meters per year (rounded to one decimal place).
  • It produces no oranges in its first 5 years.
  • Starting in its sixth year, the tree produces oranges at a rate of (height * 15 - 25) per year.
  • The tree dies after 25 years.
  • Also, follow the output in the example below.
    Example:
ot = OrangeTree.new
 23.times {ot.one_year_passes}    #in this case, the tree is 23 years old!
 
ot.one_year_passes    #live tree returns:
"This year your tree grew to 9.6m tall, and produced 119 oranges." 

ot.count_the_oranges    #live tree returns:
119 

ot.height    #live tree returns:
9.6 

ot.one_year_passes    #live tree returns:
"This year your tree grew to 10.0m tall, and produced 125 oranges."

ot.one_year_passes    #dead tree returns:
"Oh, no! The tree is too old, and has died. :("

ot.one_year_passes    #dead tree for longer than a year returns:
"A year later, the tree is still dead. :("

ot.height    #dead tree returns:
"A dead tree is not very tall. :("

ot.count_the_oranges    #dead tree returns:
"A dead tree has no oranges. :("

ot.pick_an_orange    #dead tree returns:
"A dead tree has nothing to pick. :("

Have fun!

##Based, inspired and stolen with love from "Learn to Program", by Chris Pine

Trees
Fundamentals
Refactoring

Stats:

CreatedMay 11, 2016
PublishedMay 11, 2016
Warriors Trained73
Total Skips7
Total Code Submissions113
Total Times Completed11
Ruby Completions11
Total Stars2
% of votes with a positive feedback rating50% of 4
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • srMarquinho Avatar
Ad