Skip to content

Instantly share code, notes, and snippets.

@Basti3n
Last active January 20, 2020 22:46
Show Gist options
  • Save Basti3n/53d087295fad32bbb5071a7dc9aa46b3 to your computer and use it in GitHub Desktop.
Save Basti3n/53d087295fad32bbb5071a7dc9aa46b3 to your computer and use it in GitHub Desktop.
namespace AboutComments
{
using System;
static class Product
{
public const int CAFE_PRIX = 1;
public const int ASSIETTE_PRIX = 15;
public const int SANDWICH_PRIX = 10;
public const int DESSERT_NORMAL_PRIX = 2;
public const int DESSERT_SPECIAL_PRIX = 4;
public const int PETIT_PRIX = 2;
public const int MOYEN_PRIX = 3;
public const int GRAND_PRIX = 4;
}
static class Size
{
public const string PETIT = "petit";
public const string MOYEN = "moyen";
public const string GRAND = "grand";
}
static class Formule
{
public const int ASSIETTE_NORMAL_SIZE = 18;
public const int ASSIETTE_MAX_SIZE = 21;
public const int SANDWICH_NORMAL_SIZE = 13;
public const int SANDWICH_MAX_SIZE = 16;
}
static class Constante
{
public const int EMPTY_DATA_SET = -1;
public const int ASSIETTE = 1;
public const int SANDWICH = 2;
}
public class App
{
private int total = 0;
private string type;
private string name;
private string size;
private string dsize;
private string coffee;
public App(string ptype, string pname, string psize, string pdsize, string pcoffee)
{
type = ptype;
name = pname;
size = psize;
dsize = pdsize;
coffee = pcoffee;
}
public int Compute()
{
if(isDataEmpty())
return Constante.EMPTY_DATA_SET;
if(type=="assiette")
{
total+= Product.ASSIETTE_PRIX;
AddToMenu(Constante.ASSIETTE);
}
else if(type == "sandwich") {
total+=Product.SANDWICH_PRIX;
AddToMenu(Constante.SANDWICH);
}
AddCoffe();
return total;
}
public void AddCoffe(){
if(type=="assiette" && size==Size.MOYEN && dsize=="normal" && coffee=="yes")
{
Console.Write(" avec café offert!");
} else {
total+=Product.CAFE_PRIX;
}
}
public void AddToMenu(int name){
switch(size)
{
case Size.PETIT:
total+=Product.PETIT_PRIX;
if(dsize=="normal")
{
total+=Product.DESSERT_NORMAL_PRIX;
} else {
total+=Product.DESSERT_SPECIAL_PRIX;
}
break;
case Size.MOYEN:
total+=Product.MOYEN_PRIX;
if(dsize!="normal")
{
total+=Product.DESSERT_SPECIAL_PRIX;
}
break;
case Size.GRAND:
total+=Product.GRAND_PRIX;
if(dsize=="normal")
{
total+=Product.DESSERT_NORMAL_PRIX;
} else {
Console.Write("Prix Formule Max appliquée ");
if(name == Constante.SANDWICH)
total=Formule.SANDWICH_MAX_SIZE;
else if(name == Constante.ASSIETTE)
total=Formule.ASSIETTE_MAX_SIZE;
}
break;
}
}
public bool isDataEmpty(){
if(string.IsNullOrEmpty(type+name+size+dsize+coffee))
return true;
return false;
}
}
}
using System;
using AboutComments;
namespace Clean_code
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start");
var pricing = new App("assiette","Lol","normal","normal", "no");
Console.WriteLine(pricing.Compute());
Console.WriteLine("Ended");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment