7 kyu

Happy Little Trees

Description:

Create a Tree class so I can grow a happy little tree. The tree has a trunk and branches which grow in unit sizes. Branches can start at the current trunk height. All branches grow simultaneously,

Methods to include:

  • Tree() - Constructor (trunk starts with height of 1 and no branches)
  • GrowTrunk() - Increase trunk height by 1 (add a new level on top of the tree similar to adding layers to a cake)
  • NewBranch() - Add a new branch at the current height (multiple separate branches can be added at each level)
  • GrowBranches() - All existing branches increase in length by 1
  • Ouch(int n) - The nth oldest branch is removed (the input is 1-indexed, and must be validated: if a branch does not exist or the input is not positive, do nothing)
  • Description() - Returns a string describing all the properties of the tree as seen below (replace the _ with appropiate values, )
"The tree trunk is {HEIGHT} unit(s) tall! There are {BRANCHES_COUNT} branch(es) that have position(s): {POSITIONS...} and length(s): {LENGTHS...}!"

Where HEIGHT and BRANCHES_COUNT are integers, POSITIONS... and LENGTHS... are comma-separated lists.

If there are no branches, the following string should be returned instead:

"The tree trunk is {HEIGHT} unit(s) tall! There are 0 branch(es)!"

Preloaded code for class structure:

public interface ITree
{
  void GrowTrunk();
  void GrowBranches();
  void NewBranch();
  void Ouch(int n);
  string Description();
}
Fundamentals

More By Author:

Check out these other kata created by sataman

Stats:

CreatedJan 27, 2016
PublishedJan 27, 2016
Warriors Trained437
Total Skips32
Total Code Submissions1566
Total Times Completed131
C# Completions131
Total Stars14
% of votes with a positive feedback rating75% of 32
Total "Very Satisfied" Votes19
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes3
Ad
Contributors
  • sataman Avatar
  • user5036852 Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
Ad