🎨 add exemple of code
continuous-integration/drone/push Build is passing Details

pull/15/head
Alexandre AGOSTINHO 2 years ago
parent 3d077ed432
commit 86d187e268

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -7,4 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MCTGLib\MCTGLib.csproj" />
</ItemGroup>
</Project>

@ -1,2 +1,32 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System;
using MCTG.Model;
namespace MCTG.Program;
public static class Program
{
public static void Main()
{
Console.WriteLine("Helle World!");
Recipe recipe = new Recipe(
1,
"Cookies aux pépites de chocolat",
new List<string>(new string[]{
"2 pommes",
"3L de vin",
"500g de farine"
}),
"Etape 1:\n"
+ "\tCouper les pommes\n"
+ "Etape 2:\n"
+ "\tLes disposer sur le plat et mettre le vin dessus\n"
+ "Etape 3:\n"
+ "\tMettez toute la farine ensuite, puis 4h32 au four.\n"
+ "\nDégustez c'est prêt !"
);
recipe.Display();
}
}

@ -1,7 +0,0 @@
namespace MCTGLib
{
public class Class1
{
}
}

@ -0,0 +1,60 @@
using System.Text;
namespace MCTG.Model
{
public class Recipe
{
public uint Id { get; set; }
public string Title { get; set; }
public List<string> Ingredients { get; set; }
public string Preparation { get; set; }
/// <summary>
/// Constructor of a Recipe.
/// </summary>
/// <param name="id">Identificator</param>
/// <param name="title">The name of the recipe</param>
/// <param name="ingredients">A list of ingredient needed by the preparation</param>
/// <param name="preparation">The text that explain the preparation of the recipe</param>
public Recipe(uint id, string title, List<string> ingredients, string preparation)
{
Id = id;
Title = title;
Ingredients = ingredients;
Preparation = preparation;
}
/// <summary>
/// Concatenate the list of ingredients in a single string
/// </summary>
/// <returns>The list of ingredients in string format</returns>
private string ConcatIngredients()
{
StringBuilder sb = new StringBuilder();
foreach (string str in Ingredients) sb.Append("\t- " + str + "\n");
return sb.ToString();
}
/// <summary>
/// Build a string with all elements (title, ingredients, preparation, ...)
/// </summary>
/// <returns>A string that represent the recipe</returns>
public override string ToString()
{
return $"{Title} -- id:{Id}\n\n"
+ "List of ingredient:\n"
+ ConcatIngredients() + "\n\n"
+ "Preparation:\n"
+ $"{Preparation}\n";
}
/// <summary>
/// Display the recipe in the console
/// </summary>
public void Display()
{
Console.WriteLine(this.ToString());
}
}
}
Loading…
Cancel
Save