1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
import java.util.ArrayList;
import java.util.List;
/**
* Référence et créée de nouveaux produits.
*/
public final class ProduitsEnVente {
/**
* Singleton de ProduitsEnVente utilisé pour référencer de manière unique
* les produits créés par le système.
*/
private static ProduitsEnVente produits = new ProduitsEnVente();
/**
* Liste des produits créés par ProduitsEnVente.
*/
private static List<Produit> products;
/**
* Constructeur privé qui permet à la classe de ne pas pouvoir être
* instanciée.
*/
private ProduitsEnVente() {
products = new ArrayList<Produit>();
}
public static ProduitsEnVente getInstance(){
if (produits==null){
produits=new ProduitsEnVente();
}
return produits;
}
/**
* Crée une liste de nouveaux Produit_simple.
* @param productName nom des produits à créer
* @param price prix des produits
* @param quantité nom de Produit_simple à créer
*/
public static List<Produit_simple> createProduits(String productName, double price, int quantity) {
List<Produit_simple> newProducts = new ArrayList<Produit_simple>();
for (int i = 0; i < quantity; i++) {
newProducts.add(new Produit_simple(productName, price));
}
System.out.println(quantity+" "+productName+" sont dorénavant disponibles à la commande");
produits.products.addAll(newProducts);
return newProducts;
}
/**
* Crée une liste de nouveaux Produit_compose.
* @param productName nom des produits à créer
* @param price prix des produits
* @param quantite quantite du même produit compose à créer
* @param ingredients liste des ingrédients necessaire à la préparation du produit compose (String)
* @return liste des nouveaux produits identiquement créés.
*/
public static List<Produit_compose> CuisinerProduit(String productName, double price, int quantite, List<String> ingredients) {
List<Produit_compose> newProducts = new ArrayList<Produit_compose>();
List<Ingredient> ingred = new ArrayList<Ingredient>();
for (int i=1 ; i==quantite ; i++){
ingred.clear();
int l;
for (int j=ingredients.size()-1 ; j>0; j--){
l=0;
String nom_ingred = ingredients.get(j);
for (int k = Ingredients.getStockIngredients().size()-1 ; k>0 ; k--){
if (nom_ingred.equals(Ingredients.getStockIngredients().get(k).getNom_ingredient()) && l<1 ){
Ingredients.getInstance();
ingred.add(Ingredients.getStockIngredients().get(k));
Ingredients.getStockIngredients().remove(k);
l++;
}
}
}
if (ingredients.size()==ingred.size()){
newProducts.add(new Produit_compose(productName, price, ingred));
}
else {
System.out.println("Il n'y a pas assez d'ingrédients pour préparer le produit");
}
}
ProduitsEnVente.products.addAll(newProducts);
return newProducts;
}
public static List<Produit> getProducts(){
return products;
}
public static void DecrisStock(){
String compo = "Le stock de produits est : ";
for (Produit prod : products){
compo = compo +" "+ prod.getNom_produit();
}
System.out.println(compo);
}
} |