Last active
March 10, 2020 11:29
-
-
Save MarionLeHerisson/167ef45cbc0f559133422cb494020fc4 to your computer and use it in GitHub Desktop.
Soft. Arch. Heuristics - Exercice 2 : refacto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace RCorpFoodPricer | |
{ | |
using System; | |
global PLATE_TYPE = "assiette"; | |
global SANDWICH_TYPE = "sandwich"; | |
global LARGE_SIZE = "grand"; | |
global MEDIUM_SIZE = "moyen"; | |
global SMALL_SIZE = "petit"; | |
global NORMAL_DESSERT = "normal"; | |
global SPECIAL_DESSERT = "special"; | |
array prices = [ | |
'type_price' => [ | |
PLATE_TYPE => 15, | |
SANDWICH_TYPE => 10, | |
] | |
'dessert' => [ | |
NORMAL_DESSERT => 2, | |
SPECIAL_DESSERT => 4, | |
], | |
'coffee' => 1, | |
'size' => [ | |
LARGE_SIZE => 4, | |
MEDIUM_SIZE => 3, | |
SMALL_SIZE => 2, | |
] | |
]; | |
public class App | |
{ | |
//calcule le prix payé par l'utilisateur dans le restaurant, en fonction de type de | |
//repas qu'il prend (assiette ou sandwich), de la taille de la boisson (petit, moyen, grand), du dessert et | |
//de son type (normal ou special) et si il prend un café ou pas (yes ou no). | |
//les prix sont fixes pour chaque type de chose mais des réductions peuvent s'appliquer | |
//si cela rentre dans une formule! | |
public double Compute(string type, string name, string beverage, string size, string dessert, string dsize, string coffee) | |
{ | |
int total = 0; | |
if(string.IsNullOrEmpty(type+name)) return -1; | |
if(type == PLATE_TYPE && size == MEDIUM_SIZE && dsize == NORMAL_DESSERT) | |
{ | |
total = 18; | |
} | |
else if(type == PLATE_TYPE && size == LARGE_SIZE && dsize == SPECIAL_DESSERT) | |
{ | |
total = 21; | |
} | |
else if (type = SANDWICH_TYPE && size == MEDIUM_SIZE && dsize == NORMAL_DESSERT) | |
{ | |
total = 13; | |
} | |
else if (type = SANDWICH_TYPE && size == LARGE_SIZE && dsize == SPECIAL_DESSERT) | |
{ | |
total = 16; | |
} | |
else | |
{ | |
total+=prices['type_price'][type]; | |
total += price['size'][size]; | |
total += price['dessert'][dsize]; | |
} | |
if(type==PLATE_TYPE && size==MEDIUM_SIZE && dsize==NORMAL_DESSERT && coffee=="yes") | |
{ | |
Console.Write(" avec café offert!"); | |
} else { | |
total += price['coffe']; | |
} | |
return total; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace RCorpFoodPricer | |
{ | |
using System; | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
//pour tester, lancer en ligne de commande : | |
//dotnet run -- "assiette" "couscous" "coca" "moyen" "baba" "normal" "yes" | |
var price = new App().Compute(args[0],args[1],args[2],args[3], args[4], args[5], args[6]); | |
Console.WriteLine($"Prix à payer : {price}€"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment