From ce6cd3cbbc5602863c8aaa3173cea83c957da7f6 Mon Sep 17 00:00:00 2001 From: Nicolas Fley <nicolas.fley@student.ecp.fr> Date: Wed, 5 Apr 2017 22:57:01 +0200 Subject: [PATCH] stuff added --- src/Core/MyFoodora.java | 21 +++++++++++-- src/Exception/ExceptionUnknownDishType.java | 35 +++++++++++++++++++++ src/Exception/ExceptionUnknownMealType.java | 34 ++++++++++++++++++++ src/Item/Dish.java | 20 ++++++++++++ src/Item/FactoryDish.java | 7 +++-- src/Item/FactoryMeal.java | 19 +++++++++++ src/Item/Meal.java | 30 +++++++++++++++++- src/Item/MealFactory.java | 16 ---------- src/Order/Order.java | 23 +++++++++++++- 9 files changed, 182 insertions(+), 23 deletions(-) create mode 100644 src/Exception/ExceptionUnknownDishType.java create mode 100644 src/Exception/ExceptionUnknownMealType.java create mode 100644 src/Item/FactoryMeal.java delete mode 100644 src/Item/MealFactory.java diff --git a/src/Core/MyFoodora.java b/src/Core/MyFoodora.java index f56012b..7c84450 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 0000000..d6c85ca --- /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 0000000..135e0bb --- /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 ac68bfe..5fa2635 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 e1da97d..c9ed7b5 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 0000000..b06f525 --- /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 c6741ad..9198b01 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 2e78188..0000000 --- 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 f35b236..d4717f9 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; } -- GitLab