Bottle

in #ita2 months ago

using System;
using System.Collections.Generic;

public static class BottleSong{

   static Dictionary<int, string> numWord = new Dictionary<int, string>{
      { 10, "Ten" },
      { 9, "Nine" },
      { 8, "Eight" },
      { 7, "Seven" },
      { 6, "Six" },
      { 5, "Five" },
      { 4, "Four" },
      { 3, "Three" },
      { 2, "Two" },
      { 1, "One" },
      {0, "no"}
    };

public static string [] Recite(int startBottles, int takeDown){
    List<string> listRes= new List<string>();
    string pass = "And if one green bottle should accidentally fall,";
    for(int i = 0; i < takeDown; i++){
        string bottlew = (startBottles ==1)? "bottle": "bottles";
        listRes.Add($"{numWord[startBottles]} green {bottlew} hanging on the wall,");
        listRes.Add($"{numWord[startBottles]} green {bottlew} hanging on the wall,");
        listRes.Add(pass);
        startBottles--;
        string nextbottle = (startBottles != 1)? "bottles": "bottle";
        listRes.Add($"There'll be {numWord[startBottles].ToLower()} green {nextbottle} hanging on the wall."); 
        if(i < takeDown-1)listRes.Add("");
    }
    return listRes.ToArray();
}

}