Pine's Orange Tree
Description:
Orange Tree
Make an OrangeTree class that has a
height
method that returns its height and aone_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) andpick_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
Similar Kata:
Stats:
Created | May 11, 2016 |
Published | May 11, 2016 |
Warriors Trained | 73 |
Total Skips | 7 |
Total Code Submissions | 113 |
Total Times Completed | 11 |
Ruby Completions | 11 |
Total Stars | 2 |
% of votes with a positive feedback rating | 50% of 4 |
Total "Very Satisfied" Votes | 1 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |