Write a C Program Computer Programming Task
Question Description
I’m working on a c# project and need a sample draft to help me study.
This is how the model looks:
“`
public class Ingredient
{
public string Name { get; set; }
public decimal? Percentage { get; set; }
public List<Ingredient> Ingredients { get; set; }
public Ingredient(string name, decimal? percentage)
{
Name = name;
Percentage = percentage;
Ingredients = new List<Ingredient>();
}
public override String ToString()
{
string temp = Name;
if(Percentage.HasValue)
{
temp = temp + ” ” + Percentage.ToString() + “%”;
}
return temp;
}
}
“`
This is the data in JSON format:
“`
{
“name”:”paneermeel”,
“percentage”:null,
“allergen”:false,
“ingredients”:[
{
“name”:”tarwebloem”,
“percentage”:null,
“allergen”:true,
“ingredients”:[
]
},
{
“name”:”kleurstoffen”,
“percentage”:null,
“allergen”:false,
“ingredients”:[
{
“name”:”karamel”,
“percentage”:null,
“allergen”:false,
“ingredients”:[
]
},
{
“name”:”annatto norbixine”,
“percentage”:null,
“allergen”:false,
“ingredients”:[
]
}
]
},
{
“name”:”zout”,
“percentage”:null,
“allergen”:false,
“ingredients”:[
]
}
]
}
“`
What I want is, when I call the ToString() method on the parent node (in this case ‘paneermeel’) it should return the following: “paneermeel (tarwebloem, kleurstoffen (karamel, annatto norbixine), zout)”
I know I have to apply recursion here, and the list of Ingredients needs to be put between parenthesis, and each ingredient between parenthesis needs to be separated by a comma. I really can’t seem to find a way to put this all together… Any help is greatly appreciated!
Code in description is not supported. I’ve also posted this on Stackoverflow: https://stackoverflow.com/questions/67239516/get-a…
"Place your order now for a similar assignment and have exceptional work written by our team of experts, guaranteeing you "A" results."