Skip to content
Snippets Groups Projects
Commit ce6cd3cb authored by Nicolas Fley's avatar Nicolas Fley
Browse files

stuff added

parent e20a48cb
Branches
No related tags found
No related merge requests found
...@@ -2,6 +2,12 @@ package Core; ...@@ -2,6 +2,12 @@ package Core;
import java.util.ArrayList; 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 */ /* to be deleted */
import provisoire.entities.ContextDeliveryPolicy; import provisoire.entities.ContextDeliveryPolicy;
import provisoire.entities.ContextTargetProfit; import provisoire.entities.ContextTargetProfit;
...@@ -92,11 +98,20 @@ public class MyFoodora { ...@@ -92,11 +98,20 @@ public class MyFoodora {
this.deliveryCost = deliveryCost; 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 // 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));
} }
} }
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
}
}
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
}
}
...@@ -39,4 +39,24 @@ public class Dish extends Item implements VisitablePrice{ ...@@ -39,4 +39,24 @@ public class Dish extends Item implements VisitablePrice{
vDish.setPrice(vDish.getPrice()+price); 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;
}
} }
package Item; package Item;
import Exception.ExceptionUnknownDishType;
public class FactoryDish { 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(); typeInMeal=typeInMeal.toLowerCase().trim();
switch(typeInMeal){ switch(typeInMeal){
case "dessert": case "dessert":
...@@ -10,7 +12,8 @@ public class FactoryDish { ...@@ -10,7 +12,8 @@ public class FactoryDish {
return new MainDish(_name,_typeOfFood,_price); return new MainDish(_name,_typeOfFood,_price);
case "starter": case "starter":
return new Starter(_name,_typeOfFood,_price); return new Starter(_name,_typeOfFood,_price);
default:
throw new ExceptionUnknownDishType("Error, '"+typeInMeal+"' is unkwon, try Dessert, MainDish or Starter.");
} }
return null;
} }
} }
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.");
}
}
}
...@@ -23,6 +23,7 @@ public abstract class Meal extends Item implements VisitorPrice{ ...@@ -23,6 +23,7 @@ public abstract class Meal extends Item implements VisitorPrice{
ArrayList<Dish> listDish = new ArrayList<Dish>(); ArrayList<Dish> listDish = new ArrayList<Dish>();
String [][] patternTypeInMeal; String [][] patternTypeInMeal;
private String typeOfMeal;
private double price=0; private double price=0;
...@@ -87,6 +88,12 @@ public abstract class Meal extends Item implements VisitorPrice{ ...@@ -87,6 +88,12 @@ public abstract class Meal extends Item implements VisitorPrice{
/** GETTER AND SETTER **/ /** GETTER AND SETTER **/
public String getTypeOfMeal() {
return typeOfMeal;
}
protected void setTypeOfMeal(String _typeOfMeal) {
this.typeOfMeal = _typeOfMeal;
}
public double getPrice(){ public double getPrice(){
return price; return price;
} }
...@@ -99,7 +106,6 @@ public abstract class Meal extends Item implements VisitorPrice{ ...@@ -99,7 +106,6 @@ public abstract class Meal extends Item implements VisitorPrice{
public String[][] getPatternTypeInMeal() { public String[][] getPatternTypeInMeal() {
return patternTypeInMeal; return patternTypeInMeal;
} }
protected void setPatternTypeInMeal(String[][] patternTypeInMeal) { protected void setPatternTypeInMeal(String[][] patternTypeInMeal) {
this.patternTypeInMeal = patternTypeInMeal; this.patternTypeInMeal = patternTypeInMeal;
} }
...@@ -122,4 +128,26 @@ public abstract class Meal extends Item implements VisitorPrice{ ...@@ -122,4 +128,26 @@ public abstract class Meal extends Item implements VisitorPrice{
public void visitPrice(VisitablePrice v) { public void visitPrice(VisitablePrice v) {
v.acceptPrice(this); 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;
}
} }
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;
}
}
...@@ -18,6 +18,27 @@ public class Order implements VisitorPrice{ ...@@ -18,6 +18,27 @@ public class Order implements VisitorPrice{
// TODO Auto-generated constructor stub // 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 **/ /** GETTER AND SETTER **/
public double getPrice(){ public double getPrice(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment