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

Dish and Meal logic added

parent 418c564d
No related branches found
No related tags found
No related merge requests found
/bin/ /bin/
/src/provisoire/ /src/provisoire/
/rapport/
.* .*
!.gitignore !.gitignore
\ No newline at end of file
# Foodora Java Project
This is the IS1220 2017 project, sources and documentation are in french.
## Contributors
+ Fley Nicolas
+ Ravoux Corentin
...@@ -3,7 +3,7 @@ package Cli; ...@@ -3,7 +3,7 @@ package Cli;
import java.util.Scanner; import java.util.Scanner;
public class Confirm { public class Confirm {
Scanner reader = new Scanner(System.in); static Scanner reader = new Scanner(System.in);
public static boolean text(String str){ public static boolean text(String str){
System.out.println(str); System.out.println(str);
System.out.println("(Y)es/(N)o : "); System.out.println("(Y)es/(N)o : ");
......
package Item;
public class Dessert extends Dish {
public Dessert(String name, String typeOfFood, double _price) {
super(name, typeOfFood, _price);
this.setTypeInMeal("Dessert");
}
}
...@@ -2,11 +2,32 @@ package Item; ...@@ -2,11 +2,32 @@ package Item;
public class Dish extends Item implements VisitablePrice{ public class Dish extends Item implements VisitablePrice{
public Dish(String name, String type) { private String typeInMeal;
super(name, type); private double price;
/** CONSTURCTOR **/
public Dish(String name, String typeOfFood, double _price) {
super(name, typeOfFood);
price = _price;
} }
private double 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) { public double acceptPrice(VisitorPrice v) {
return v.visitPrice(this); return v.visitPrice(this);
......
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;
}
}
package Item;
public class FullMeal extends Meal {
public FullMeal(String name, String typeOfFood) {
super(name, typeOfFood);
String [][] pattern = {{"Starter","Dessert"},{"MainDish"}};
this.setPatternTypeInMeal(pattern);
}
}
package Item;
public class HalfMeal extends Meal {
public HalfMeal(String name, String typeOfFood) {
super(name, typeOfFood);
String [][] pattern = {{"Starter","Dessert"},{"MainDish"}};
this.setPatternTypeInMeal(pattern);
}
}
...@@ -2,15 +2,15 @@ package Item; ...@@ -2,15 +2,15 @@ package Item;
public abstract class Item implements VisitablePrice { public abstract class Item implements VisitablePrice {
String type; String typeOfFood;
String name; String name;
/** CONSTRUCTOR **/ /** CONSTRUCTOR **/
public Item(String name,String type) { public Item(String _name,String _typeOfFood) {
super(); super();
this.type = type; this.typeOfFood = _typeOfFood;
this.name = name; this.name = _name;
} }
/** METHODS **/ /** METHODS **/
...@@ -18,16 +18,16 @@ public abstract class Item implements VisitablePrice { ...@@ -18,16 +18,16 @@ public abstract class Item implements VisitablePrice {
/** GETTER & SETTER **/ /** GETTER & SETTER **/
public String getType() { public String getTypeOfFood() {
return type; return typeOfFood;
} }
public void setType(String type) { public void setTypeOfFood(String _typeOfFood) {
this.type = type; this.typeOfFood = _typeOfFood;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String _name) {
this.name = name; this.name = _name;
} }
} }
package Item;
public class MainDish extends Dish {
public MainDish(String name, String typeOfFood, double _price) {
super(name, typeOfFood, _price);
this.setTypeInMeal("MainDish");
}
}
...@@ -2,46 +2,60 @@ package Item; ...@@ -2,46 +2,60 @@ package Item;
import java.util.ArrayList; 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>(); ArrayList<Dish> listDish = new ArrayList<Dish>();
String [][] patternTypeInMeal;
private double price=0; private double price=0;
public Meal(String name,String type) { /** CONSTRUCTORS **/
super(name,type);
public Meal(String name,String typeOfFood) {
super(name,typeOfFood);
} }
public void addDish(ArrayList<Dish> listDishRestaurant, String name){ /** add and remove dishes **/
for(Dish dish: listDishRestaurant){
if(dish.getName()==name) public void addDish(Dish dish){
System.out.println("Adding "+dish.toString()+" to meal : "+this.getName()); if(dish.getTypeOfFood() != this.getTypeOfFood()){
if(!listDish.contains(dish)){ System.out.println("Trying to add "+dish.getTypeOfFood()+" in "+this.getTypeOfFood()+" menu, resulted in error.");
listDish.add(dish); }else{
System.out.println("Dish added."); int idInMenu=-1;
int idInMenuInc=0;
for(String[] tabOfType : this.getPatternTypeInMeal()){
for(String typeFromPatternType : tabOfType){
if(typeFromPatternType==dish.getTypeInMeal()){
idInMenu=idInMenuInc;
} }
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.");
} }
idInMenuInc+=1;
} }
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 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.");
} }
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.");
} }
} }
} }
...@@ -69,9 +83,21 @@ public class Meal extends Item implements VisitorPrice{ ...@@ -69,9 +83,21 @@ public class Meal extends Item implements VisitorPrice{
} }
} }
/** GETTER AND SETTER **/
public double getPrice(){ public double getPrice(){
return price; return price;
} }
public ArrayList<Dish> getListDish() {
return listDish;
}
public String[][] getPatternTypeInMeal() {
return patternTypeInMeal;
}
protected void setPatternTypeInMeal(String[][] patternTypeInMeal) {
this.patternTypeInMeal = patternTypeInMeal;
}
/** VISIT LOGIC **/ /** VISIT LOGIC **/
......
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;
}
}
package Item;
public class Starter extends Dish {
public Starter(String name, String typeOfFood, double _price) {
super(name, typeOfFood, _price);
this.setTypeInMeal("Starter");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment