diff --git a/.gitignore b/.gitignore index 460fbf47b57a7ecc7626b3c7dde496b61db2824a..239de2dc57e47706616e9f64c5a3b127da0b1896 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /bin/ /src/provisoire/ +/rapport/ .* !.gitignore \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d91abbe15cccaa4f92482137ba2c7abf70ad7f1f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Foodora Java Project +This is the IS1220 2017 project, sources and documentation are in french. +## Contributors ++ Fley Nicolas ++ Ravoux Corentin diff --git a/src/Cli/Confirm.java b/src/Cli/Confirm.java index 3911b1d38b96d1e2372307510d58efe83bfb158c..abd707b7a1023e4c16f3141cc15bd068da9597c1 100644 --- a/src/Cli/Confirm.java +++ b/src/Cli/Confirm.java @@ -3,7 +3,7 @@ package Cli; import java.util.Scanner; public class Confirm { - Scanner reader = new Scanner(System.in); + static Scanner reader = new Scanner(System.in); public static boolean text(String str){ System.out.println(str); System.out.println("(Y)es/(N)o : "); diff --git a/src/Item/Dessert.java b/src/Item/Dessert.java new file mode 100644 index 0000000000000000000000000000000000000000..a1e74acbd3badd00c51c9437a15dab7ae00c4416 --- /dev/null +++ b/src/Item/Dessert.java @@ -0,0 +1,8 @@ +package Item; + +public class Dessert extends Dish { + public Dessert(String name, String typeOfFood, double _price) { + super(name, typeOfFood, _price); + this.setTypeInMeal("Dessert"); + } +} diff --git a/src/Item/Dish.java b/src/Item/Dish.java index 5df2a486d905e0511ed3fa2107b291078cd0cc01..b6669d4103ea8a94a454eaa029dba3c6066e6821 100644 --- a/src/Item/Dish.java +++ b/src/Item/Dish.java @@ -2,12 +2,33 @@ package Item; public class Dish extends Item implements VisitablePrice{ - public Dish(String name, String type) { - super(name, type); - } - + private String typeInMeal; private double price; + /** CONSTURCTOR **/ + + public Dish(String name, String typeOfFood, double _price) { + super(name, typeOfFood); + price = _price; + } + + /** GETTER AND SETTER **/ + + public String getTypeInMeal() { + return typeInMeal; + } + protected void setTypeInMeal(String _typeInMeal) { + this.typeInMeal = _typeInMeal; + } + public double getPrice() { + return price; + } + public void setPrice(double _price) { + this.price = _price; + } + + /** VISIT LOGIC **/ + public double acceptPrice(VisitorPrice v) { return v.visitPrice(this); } diff --git a/src/Item/FactoryDish.java b/src/Item/FactoryDish.java new file mode 100644 index 0000000000000000000000000000000000000000..e1da97d69b5cf8f37e3a058ce4315e134c5d0052 --- /dev/null +++ b/src/Item/FactoryDish.java @@ -0,0 +1,16 @@ +package Item; + +public class FactoryDish { + public Dish createDishFactory(String typeInMeal, String _name, String _typeOfFood, double _price){ + typeInMeal=typeInMeal.toLowerCase().trim(); + switch(typeInMeal){ + case "dessert": + return new Dessert(_name,_typeOfFood,_price); + case "maindish": + return new MainDish(_name,_typeOfFood,_price); + case "starter": + return new Starter(_name,_typeOfFood,_price); + } + return null; + } +} diff --git a/src/Item/FullMeal.java b/src/Item/FullMeal.java new file mode 100644 index 0000000000000000000000000000000000000000..04ec7983158c1b38cb0112ed0223c2971f32d05d --- /dev/null +++ b/src/Item/FullMeal.java @@ -0,0 +1,11 @@ +package Item; + +public class FullMeal extends Meal { + + public FullMeal(String name, String typeOfFood) { + super(name, typeOfFood); + String [][] pattern = {{"Starter","Dessert"},{"MainDish"}}; + this.setPatternTypeInMeal(pattern); + } + +} diff --git a/src/Item/HalfMeal.java b/src/Item/HalfMeal.java new file mode 100644 index 0000000000000000000000000000000000000000..d68d5c44b83f93fb72da75ba2121207b26b0324d --- /dev/null +++ b/src/Item/HalfMeal.java @@ -0,0 +1,11 @@ +package Item; + +public class HalfMeal extends Meal { + + public HalfMeal(String name, String typeOfFood) { + super(name, typeOfFood); + String [][] pattern = {{"Starter","Dessert"},{"MainDish"}}; + this.setPatternTypeInMeal(pattern); + } + +} diff --git a/src/Item/Item.java b/src/Item/Item.java index 9c2b1117e721f7efcb5078479dd0dfe211d74c2d..58010116ea5b2bad07789556a83d8cb67efd57a9 100644 --- a/src/Item/Item.java +++ b/src/Item/Item.java @@ -2,15 +2,15 @@ package Item; public abstract class Item implements VisitablePrice { - String type; + String typeOfFood; String name; /** CONSTRUCTOR **/ - public Item(String name,String type) { + public Item(String _name,String _typeOfFood) { super(); - this.type = type; - this.name = name; + this.typeOfFood = _typeOfFood; + this.name = _name; } /** METHODS **/ @@ -18,16 +18,16 @@ public abstract class Item implements VisitablePrice { /** GETTER & SETTER **/ - public String getType() { - return type; + public String getTypeOfFood() { + return typeOfFood; } - public void setType(String type) { - this.type = type; + public void setTypeOfFood(String _typeOfFood) { + this.typeOfFood = _typeOfFood; } public String getName() { return name; } - public void setName(String name) { - this.name = name; + public void setName(String _name) { + this.name = _name; } } diff --git a/src/Item/MainDish.java b/src/Item/MainDish.java new file mode 100644 index 0000000000000000000000000000000000000000..b5d8bcd1ee7f4ec40e017fb5d5b97f8ecad787f5 --- /dev/null +++ b/src/Item/MainDish.java @@ -0,0 +1,8 @@ +package Item; + +public class MainDish extends Dish { + public MainDish(String name, String typeOfFood, double _price) { + super(name, typeOfFood, _price); + this.setTypeInMeal("MainDish"); + } +} diff --git a/src/Item/Meal.java b/src/Item/Meal.java index eabbafefef1a2cbe101d24fb99775cb6cf5b3e81..e1ae4ef66193177bdbd518e8f7fd122121cea541 100644 --- a/src/Item/Meal.java +++ b/src/Item/Meal.java @@ -2,48 +2,62 @@ package Item; import java.util.ArrayList; -public class Meal extends Item implements VisitorPrice{ + +/** + * + * This Meal class is created by the use of a pattern given in the constructor of + * subClasses, this pattern must consist on an array, each case contain an obligatory + * typeOfMeal (starter,mainDish...), if the user have the choice between two typeOfMeal + * it can be implemented by using a subArray. + * For exemple, the patterns below show how a full meal may be created and then a half meal : + * fullMealPattern={{"Starter"},{"MainDish"},{"Dessert"}} + * halfMealPattern={{"Starter","Dessert"},{"MainDish"}} + * + * We may create a children meal very easily : + * chlidrenMealPattern={{"MainDish"},{"Dessert"},{"Drink"}} + * + */ +public abstract class Meal extends Item implements VisitorPrice{ ArrayList<Dish> listDish = new ArrayList<Dish>(); + String [][] patternTypeInMeal; private double price=0; - public Meal(String name,String type) { - super(name,type); + /** CONSTRUCTORS **/ + + public Meal(String name,String typeOfFood) { + super(name,typeOfFood); } - public void addDish(ArrayList<Dish> listDishRestaurant, String name){ - for(Dish dish: listDishRestaurant){ - if(dish.getName()==name) - System.out.println("Adding "+dish.toString()+" to meal : "+this.getName()); - if(!listDish.contains(dish)){ - listDish.add(dish); - System.out.println("Dish added."); - } - else{ - System.out.println("This dish is in this menu."); - if(Cli.Confirm.text("Do you really want to add "+dish.toString()+" ?")){ - listDish.add(dish); - System.out.println("Dish added."); + /** add and remove dishes **/ + + public void addDish(Dish dish){ + if(dish.getTypeOfFood() != this.getTypeOfFood()){ + System.out.println("Trying to add "+dish.getTypeOfFood()+" in "+this.getTypeOfFood()+" menu, resulted in error."); + }else{ + int idInMenu=-1; + int idInMenuInc=0; + for(String[] tabOfType : this.getPatternTypeInMeal()){ + for(String typeFromPatternType : tabOfType){ + if(typeFromPatternType==dish.getTypeInMeal()){ + idInMenu=idInMenuInc; } } - } - } - public void addDish(ArrayList<Dish> listDishRestaurant, int num){ - Dish dish = listDishRestaurant.get(num); - System.out.println("Adding "+dish.toString()+" to meal : "+this.getName()); - if(dish.getName()==name) - if(!listDish.contains(dish)){ - listDish.add(dish); - System.out.println("Dish added."); + idInMenuInc+=1; } - else{ - System.out.println("This dish is in this menu."); - if(Cli.Confirm.text("Do you really want to add "+dish.toString()+" ?")){ - listDish.add(dish); - System.out.println("Dish added."); + if(idInMenu>-1){ + if(listDish.get(idInMenu)==null){ + listDish.set(idInMenu, dish); + } + else{ + if(Cli.Confirm.text("This dish : "+listDish.get(idInMenu).toString()+" exists already. Do you want to replace it ?))")){ + listDish.remove(idInMenu); + listDish.add(idInMenu, dish); + } } } + } } public void removeDish(String name){ @@ -69,9 +83,21 @@ public class Meal extends Item implements VisitorPrice{ } } + /** GETTER AND SETTER **/ + public double getPrice(){ return price; } + public ArrayList<Dish> getListDish() { + return listDish; + } + public String[][] getPatternTypeInMeal() { + return patternTypeInMeal; + } + + protected void setPatternTypeInMeal(String[][] patternTypeInMeal) { + this.patternTypeInMeal = patternTypeInMeal; + } /** VISIT LOGIC **/ diff --git a/src/Item/MealFactory.java b/src/Item/MealFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..2e781888692e16b51c7f7b8f3dbc3a810d988d34 --- /dev/null +++ b/src/Item/MealFactory.java @@ -0,0 +1,16 @@ +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/Item/Starter.java b/src/Item/Starter.java new file mode 100644 index 0000000000000000000000000000000000000000..8c395e97d1da1ec491d5861a1870818ec055bef4 --- /dev/null +++ b/src/Item/Starter.java @@ -0,0 +1,10 @@ +package Item; + +public class Starter extends Dish { + + public Starter(String name, String typeOfFood, double _price) { + super(name, typeOfFood, _price); + this.setTypeInMeal("Starter"); + } + +}