diff --git a/src/Core/MyFoodora.java b/src/Core/MyFoodora.java index f56012b485a65041b4c794323bf0c28466e55f29..7c8445070abf191d84d3a8c307fd425c15715146 100644 --- a/src/Core/MyFoodora.java +++ b/src/Core/MyFoodora.java @@ -2,6 +2,12 @@ package Core; import java.util.ArrayList; +import Exception.ExceptionUnknownDishType; +import Exception.ExceptionUnknownMealType; +import Item.Dish; +import Item.FactoryDish; +import Item.FactoryMeal; +import Item.Meal; /* to be deleted */ import provisoire.entities.ContextDeliveryPolicy; import provisoire.entities.ContextTargetProfit; @@ -92,11 +98,20 @@ public class MyFoodora { this.deliveryCost = deliveryCost; } - /** END GENERIC GETTER AND SETTER **/ + /** END GENERIC GETTER AND SETTER + * @throws ExceptionUnknownMealType + * @throws ExceptionUnknownDishType **/ - public static void main(String[] args) { + public static void main(String[] args) throws ExceptionUnknownMealType, ExceptionUnknownDishType { // TODO Auto-generated method stub - + FactoryDish dishFactory = new FactoryDish(); + FactoryMeal mealFactory = new FactoryMeal(); + Dish d1 = dishFactory.createDish("MainDish", "French Fries", "Vegan", 3.0); + Dish d2 = dishFactory.createDish("MainDish", "French Fries", "Vegan", 3.0); + Meal m1 = mealFactory.createMeal("HalfMeal"); + Meal m2 = mealFactory.createMeal("HalfMeal"); + System.out.println(d1.equals(d2)); + System.out.println(m1.equals(m2)); } } diff --git a/src/Exception/ExceptionUnknownDishType.java b/src/Exception/ExceptionUnknownDishType.java new file mode 100644 index 0000000000000000000000000000000000000000..d6c85ca6d9a4014751e735c67e03ea199a26981a --- /dev/null +++ b/src/Exception/ExceptionUnknownDishType.java @@ -0,0 +1,35 @@ +package Exception; + +public class ExceptionUnknownDishType extends Exception { + + /** + * + */ + private static final long serialVersionUID = 3147255315073491030L; + + public ExceptionUnknownDishType() { + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownDishType(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownDishType(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownDishType(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownDishType(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/Exception/ExceptionUnknownMealType.java b/src/Exception/ExceptionUnknownMealType.java new file mode 100644 index 0000000000000000000000000000000000000000..135e0bb0c1aa24992b39da0fbf663c124523a751 --- /dev/null +++ b/src/Exception/ExceptionUnknownMealType.java @@ -0,0 +1,34 @@ +package Exception; + +public class ExceptionUnknownMealType extends Exception { + + /** + * + */ + private static final long serialVersionUID = 8804200291546048941L; + + public ExceptionUnknownMealType() { + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownMealType(String arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownMealType(Throwable arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownMealType(String arg0, Throwable arg1) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + public ExceptionUnknownMealType(String arg0, Throwable arg1, boolean arg2, boolean arg3) { + super(arg0, arg1, arg2, arg3); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/Item/Dish.java b/src/Item/Dish.java index ac68bfef911fd19356ba822c9553ad15edc054dd..5fa2635b3c591f8c1d2b58fde07162d20c067610 100644 --- a/src/Item/Dish.java +++ b/src/Item/Dish.java @@ -39,4 +39,24 @@ public class Dish extends Item implements VisitablePrice{ vDish.setPrice(vDish.getPrice()+price); } } + + /** OVERRIDE **/ + @Override + public boolean equals(Object d){ + if(d instanceof Dish){ + Dish dish = (Dish) d; + if(dish.getPrice()==price && dish.getName()==name && dish.getTypeOfFood()==typeOfFood && dish.getTypeInMeal()==typeInMeal) + return true; + } + return false; + } + @Override + public String toString(){ + String s=""; + s+="\nName : "+name; + s+=", type of food : "+typeOfFood; + s+=", type : "+typeInMeal; + s+=", price : "+price; + return s; + } } diff --git a/src/Item/FactoryDish.java b/src/Item/FactoryDish.java index e1da97d69b5cf8f37e3a058ce4315e134c5d0052..c9ed7b51268e9c16ec9d1d19e9249d41fe7bccbb 100644 --- a/src/Item/FactoryDish.java +++ b/src/Item/FactoryDish.java @@ -1,7 +1,9 @@ package Item; +import Exception.ExceptionUnknownDishType; + public class FactoryDish { - public Dish createDishFactory(String typeInMeal, String _name, String _typeOfFood, double _price){ + public Dish createDish(String typeInMeal, String _name, String _typeOfFood, double _price) throws ExceptionUnknownDishType{ typeInMeal=typeInMeal.toLowerCase().trim(); switch(typeInMeal){ case "dessert": @@ -10,7 +12,8 @@ public class FactoryDish { return new MainDish(_name,_typeOfFood,_price); case "starter": return new Starter(_name,_typeOfFood,_price); + default: + throw new ExceptionUnknownDishType("Error, '"+typeInMeal+"' is unkwon, try Dessert, MainDish or Starter."); } - return null; } } diff --git a/src/Item/FactoryMeal.java b/src/Item/FactoryMeal.java new file mode 100644 index 0000000000000000000000000000000000000000..b06f5255ca1cdbc1a6023920fd951633352e21f7 --- /dev/null +++ b/src/Item/FactoryMeal.java @@ -0,0 +1,19 @@ +package Item; + +import Exception.ExceptionUnknownMealType; + +public class FactoryMeal { + + public Meal createMeal(String typeOfMeal) throws ExceptionUnknownMealType{ + typeOfMeal=typeOfMeal.toLowerCase().trim(); + switch(typeOfMeal){ + case "halfmeal": + return new HalfMeal("typeOfMeal","standard"); + case "fullmeal": + return new FullMeal("typeOfMeal","standard"); + default: + throw new ExceptionUnknownMealType("Error, '"+typeOfMeal+"' is unkwon, try HalfMeal or FullMeal."); + } + } + +} diff --git a/src/Item/Meal.java b/src/Item/Meal.java index c6741ad86ef6a35251de06cb04f1b86c413c5570..9198b01898cf8aee97275b924742707cff08fb85 100644 --- a/src/Item/Meal.java +++ b/src/Item/Meal.java @@ -23,6 +23,7 @@ public abstract class Meal extends Item implements VisitorPrice{ ArrayList<Dish> listDish = new ArrayList<Dish>(); String [][] patternTypeInMeal; + private String typeOfMeal; private double price=0; @@ -87,6 +88,12 @@ public abstract class Meal extends Item implements VisitorPrice{ /** GETTER AND SETTER **/ + public String getTypeOfMeal() { + return typeOfMeal; + } + protected void setTypeOfMeal(String _typeOfMeal) { + this.typeOfMeal = _typeOfMeal; + } public double getPrice(){ return price; } @@ -99,7 +106,6 @@ public abstract class Meal extends Item implements VisitorPrice{ public String[][] getPatternTypeInMeal() { return patternTypeInMeal; } - protected void setPatternTypeInMeal(String[][] patternTypeInMeal) { this.patternTypeInMeal = patternTypeInMeal; } @@ -122,4 +128,26 @@ public abstract class Meal extends Item implements VisitorPrice{ public void visitPrice(VisitablePrice v) { v.acceptPrice(this); } + + /** OVERRIDE **/ + @Override + public boolean equals(Object m){ + if(m instanceof Meal){ + Meal meal = (Meal) m; + if(meal.getTypeOfMeal()==typeOfMeal) + return true; + } + return false; + } + @Override + public String toString(){ + String s=""; + s+="Menu : "+name; + s+="\nType of Food : "+typeOfFood; + s+="\nThis Menu contain : "; + for(Dish d:listDish){ + s+="\n"+d.toString(); + } + return s; + } } diff --git a/src/Item/MealFactory.java b/src/Item/MealFactory.java deleted file mode 100644 index 2e781888692e16b51c7f7b8f3dbc3a810d988d34..0000000000000000000000000000000000000000 --- a/src/Item/MealFactory.java +++ /dev/null @@ -1,16 +0,0 @@ -package Item; - -public class MealFactory { - - public Meal createMeal(String typeOfMeal, String _name, String _typeOfFood){ - typeOfMeal=typeOfMeal.toLowerCase().trim(); - switch(typeOfMeal){ - case "halfmeal": - return new HalfMeal(_name,_typeOfFood); - case "fullmeal": - return new FullMeal(_name,_typeOfFood); - } - return null; - } - -} diff --git a/src/Order/Order.java b/src/Order/Order.java index f35b236ed9b925abbb4187929bf4b7615f45ec97..d4717f95226f02414bdc175d9356f572430b01d8 100644 --- a/src/Order/Order.java +++ b/src/Order/Order.java @@ -18,9 +18,30 @@ public class Order implements VisitorPrice{ // TODO Auto-generated constructor stub } + /** AND & REMOVE **/ + + public void add(Dish d){ + listDish.add(d); + } + public void add(Meal m){ + listMeal.add(m); + } + public void remove(Dish d){ + listDish.remove(d); + } + public void remove(Meal m){ + listMeal.remove(m); + } + public void removeDishById(int d){ + listDish.remove(d); + } + public void removeMealById(int m){ + listMeal.remove(m); + } + /** GETTER AND SETTER **/ - public double getPrice() { + public double getPrice(){ return price; }