From 8ba8b2c1d54edcca6b5a190f5255e0fbf077ce54 Mon Sep 17 00:00:00 2001
From: Nicolas Fley <nicolas.fley@student.ecp.fr>
Date: Wed, 5 Apr 2017 23:04:13 +0200
Subject: [PATCH] corentin work

---
 src/Cli/Confirm.java      |  4 ++-
 src/Cli/Input.java        | 17 +++++++++
 src/Core/MyFoodora.java   | 21 ++---------
 src/Item/Dish.java        | 20 -----------
 src/Item/FactoryDish.java |  7 ++--
 src/Item/Meal.java        | 30 +---------------
 src/Item/MealFactory.java | 16 +++++++++
 src/Order/Order.java      | 23 +-----------
 src/User/Courier.java     | 61 ++++++++++++++++++++++++++++++++
 src/User/Customer.java    | 74 ++++++++++++++++++++++++++++++++++++++-
 src/User/ListUser.java    | 21 +++++++++++
 src/User/Restaurant.java  | 71 ++++++++++++++++++++++++++++++++++---
 12 files changed, 265 insertions(+), 100 deletions(-)
 create mode 100644 src/Cli/Input.java
 create mode 100644 src/Item/MealFactory.java
 create mode 100644 src/User/Courier.java
 create mode 100644 src/User/ListUser.java

diff --git a/src/Cli/Confirm.java b/src/Cli/Confirm.java
index abd707b..4a3448c 100644
--- a/src/Cli/Confirm.java
+++ b/src/Cli/Confirm.java
@@ -3,11 +3,13 @@ package Cli;
 import java.util.Scanner;
 
 public class Confirm {
-	static Scanner reader = new Scanner(System.in);
+	
 	public static boolean text(String str){
+		Scanner reader = new Scanner(System.in);
 		System.out.println(str);
 		System.out.println("(Y)es/(N)o : ");
 		String answer = reader.nextLine();
+		reader.close();
 		if(answer=="y" || answer == "Y" || answer == "o" || answer == "O")
 			return true;
 		return false;
diff --git a/src/Cli/Input.java b/src/Cli/Input.java
new file mode 100644
index 0000000..d890ada
--- /dev/null
+++ b/src/Cli/Input.java
@@ -0,0 +1,17 @@
+package Cli;
+
+import java.util.ArrayList;
+import java.util.Scanner;
+
+public class Input {
+	
+	public static String string(String question){
+		Scanner reader = new Scanner(System.in);
+		System.out.println(question);
+		System.out.println("Type the name");
+		String string = reader.nextLine();
+		reader.close();
+		return string;
+	}
+
+}
diff --git a/src/Core/MyFoodora.java b/src/Core/MyFoodora.java
index 7c84450..f56012b 100644
--- a/src/Core/MyFoodora.java
+++ b/src/Core/MyFoodora.java
@@ -2,12 +2,6 @@ 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;
@@ -98,20 +92,11 @@ public class MyFoodora {
 		this.deliveryCost = deliveryCost;
 	}
 
-	/** END GENERIC GETTER AND SETTER 
-	 * @throws ExceptionUnknownMealType 
-	 * @throws ExceptionUnknownDishType **/
+	/** END GENERIC GETTER AND SETTER **/
 
-	public static void main(String[] args) throws ExceptionUnknownMealType, ExceptionUnknownDishType {
+	public static void main(String[] args) {
 		// 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/Item/Dish.java b/src/Item/Dish.java
index 5fa2635..ac68bfe 100644
--- a/src/Item/Dish.java
+++ b/src/Item/Dish.java
@@ -39,24 +39,4 @@ 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 c9ed7b5..e1da97d 100644
--- a/src/Item/FactoryDish.java
+++ b/src/Item/FactoryDish.java
@@ -1,9 +1,7 @@
 package Item;
 
-import Exception.ExceptionUnknownDishType;
-
 public class FactoryDish {
-	public Dish createDish(String typeInMeal, String _name, String _typeOfFood, double _price) throws ExceptionUnknownDishType{
+	public Dish createDishFactory(String typeInMeal, String _name, String _typeOfFood, double _price){
 		typeInMeal=typeInMeal.toLowerCase().trim();
 		switch(typeInMeal){
 		case "dessert":
@@ -12,8 +10,7 @@ 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/Meal.java b/src/Item/Meal.java
index 9198b01..c6741ad 100644
--- a/src/Item/Meal.java
+++ b/src/Item/Meal.java
@@ -23,7 +23,6 @@ public abstract class Meal extends Item implements VisitorPrice{
 	
 	ArrayList<Dish> listDish = new ArrayList<Dish>();
 	String [][] patternTypeInMeal;
-	private String typeOfMeal;
 	
 	private double price=0;
 	
@@ -88,12 +87,6 @@ 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;
 	}
@@ -106,6 +99,7 @@ public abstract class Meal extends Item implements VisitorPrice{
 	public String[][] getPatternTypeInMeal() {
 		return patternTypeInMeal;
 	}
+
 	protected void setPatternTypeInMeal(String[][] patternTypeInMeal) {
 		this.patternTypeInMeal = patternTypeInMeal;
 	}
@@ -128,26 +122,4 @@ 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
new file mode 100644
index 0000000..2e78188
--- /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/Order/Order.java b/src/Order/Order.java
index d4717f9..f35b236 100644
--- a/src/Order/Order.java
+++ b/src/Order/Order.java
@@ -18,30 +18,9 @@ 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;
 	}
 
diff --git a/src/User/Courier.java b/src/User/Courier.java
new file mode 100644
index 0000000..967c612
--- /dev/null
+++ b/src/User/Courier.java
@@ -0,0 +1,61 @@
+package User;
+
+import Core.MyFoodora;
+import Others.Adress;
+import Others.Position;
+
+public class Courier extends HumanUser {
+	
+	private Position position;
+	private long nbOfLivraison;
+	private boolean available;
+	
+	/** CONSTRUCTOR **/
+	
+	
+	public Courier(long phoneNumber, String name, String username, String mail, String password,
+			Adress adress, boolean activated, String birthdayDate, String surname,Position position, boolean available) {
+		super(phoneNumber, name, username, mail, password, adress, activated, birthdayDate, surname);
+		this.position = position;
+		this.nbOfLivraison = 0;
+		this.available = available;
+	}
+
+
+	public Position getPosition() {
+		return position;
+	}
+
+
+	public void setPosition(Position position) {
+		this.position = position;
+	}
+
+
+	public long getNbOfLivraison() {
+		return nbOfLivraison;
+	}
+	
+
+	public void setAvailable(boolean available) {
+		this.available = available;
+	}
+	
+	public void register(MyFoodora foodora){
+		
+	}
+	
+	public void unregister(MyFoodora foodora){
+		
+	}
+	
+	public void acceptDelivery(){
+		
+	}
+	
+	public void refuseDelivery(){
+		
+	}
+	
+
+}
diff --git a/src/User/Customer.java b/src/User/Customer.java
index 4ed3b45..017e733 100644
--- a/src/User/Customer.java
+++ b/src/User/Customer.java
@@ -1,5 +1,8 @@
 package User;
 
+import java.util.Scanner;
+import Cli.Confirm;
+
 import Cards.BasicFidelityCard;
 import Cards.FidelityCard;
 import Cards.LotteryFidelityCard;
@@ -10,6 +13,10 @@ import Others.Adress;
 import Others.Historique;
 import Others.IDCard;
 import Order.Order;
+import Cli.Input;
+import Item.FactoryDish;
+import Item.Meal;
+import Item.MealFactory;
 
 public class Customer extends HumanUser implements VisiterCard {
 
@@ -38,7 +45,72 @@ public class Customer extends HumanUser implements VisiterCard {
 		return "Customer [spamAgree=" + spamAgree + ", historique=" + historique + ", card=" + card + "]";
 	}
 	
-	public void placeOrder(Order order, Restaurant restaurant){
+	public void placeOrder(Restaurant restaurant){
+		Order order = new Order();
+		System.out.println(restaurant.toString());
+		do {
+			if (Confirm.text("Do you want a Meal?")){
+				System.out.println("listdesMeal"); // � faire
+				String choice = Cli.Input.string("Which meal do you want?");
+				boolean isIn = false;
+				for(Meal meal : restaurant.listOfMeal){
+					if(meal.toString() == choice){
+						isIn = true;
+					}
+				}
+				if (isIn == false){
+					System.out.println("This meal isn't propose by this restaurant");
+				}
+				else {
+					if(choice == "FullMeal"){
+						System.out.println("listedesDish"); //� faire
+						String entry1 = Cli.Input.string("Which entry do you want in your meal?");
+						String main1 = Cli.Input.string("Which main do you want in your meal?");
+						String dessert1 = Cli.Input.string("Which dessert do you want in your meal?");
+						MealFactory factory1 = new MealFactory();
+						//Meal newmeal = factory1.createMeal("fullmeal", _name, _typeOfFood)
+					}
+					if (choice == "HalfMeal"){
+						System.out.println("listedesDish"); //� faire
+						String typeOfFormule = Cli.Input.string("Which formula do you want? Entry/Main(EM) or Main/Dessert(MD)");
+						if(typeOfFormule == "EM"){
+							String entry2 = Cli.Input.string("Which entry do you want in your meal?");
+							String main2 = Cli.Input.string("Which main do you want in your meal?");
+							MealFactory factory2 = new MealFactory();
+							//Meal newmeal = factory2.createMeal("halfmeal"
+						}
+						else if(typeOfFormule == "MD"){
+							String main3 = Cli.Input.string("Which main do you want in your meal?");
+							String dessert3 = Cli.Input.string("Which dessert do you want in your meal?");
+							MealFactory factory3 = new MealFactory();
+							//Meal newmeal = factory3.createMeal("halfmeal"
+						}
+						else{
+							System.out.println("This type of Meal is not available");
+						}
+					}
+
+					}
+				
+				
+			}
+			else if (Confirm.text("Do you want a dish?")){
+				System.out.println("listOfDish");
+				String dish = Cli.Input.string("Which dish do you want ?");
+				FactoryDish factory4 = new FactoryDish();
+				
+		
+				
+			}
+			
+			
+		} while (Confirm.text("Do you want something else ?"));
+		System.out.println("Do you want a Meal? (y)es or (n)o");
+		Scanner sc = new Scanner(System.in);
+		String choice = sc.nextLine();
+		if (Confirm.text("Do you want a Meal?")){
+			
+		}
 		
 	}
 	
diff --git a/src/User/ListUser.java b/src/User/ListUser.java
new file mode 100644
index 0000000..daf3392
--- /dev/null
+++ b/src/User/ListUser.java
@@ -0,0 +1,21 @@
+package User;
+
+import java.util.ArrayList;
+
+
+	
+
+	public class ListUser<T>{
+		private ArrayList<T> listUser = new ArrayList<T>();
+		
+		public void addUser(T e){
+			listUser.add(e);
+		}
+		public void removeUser(int id){
+			// todo
+		}
+		public ArrayList<T> getList(){
+			return listUser;
+		}
+	}
+	
\ No newline at end of file
diff --git a/src/User/Restaurant.java b/src/User/Restaurant.java
index 971ba54..2e68152 100644
--- a/src/User/Restaurant.java
+++ b/src/User/Restaurant.java
@@ -1,24 +1,87 @@
 package User;
 
+import java.util.ArrayList;
+
+import Item.Dish;
+import Item.Meal;
 import Others.Adress;
 
 public class Restaurant extends MoralUser {
 	
-	//ArrayList<Meal> listOfMeal;
+	
+	
+	ArrayList<Meal> listOfMeal;
+	ArrayList<Dish> listOfDish;
+	
+	/** CONSTRUCTOR **/
 	
 	public Restaurant(long phoneNumber, String name, String username, String mail, String password,
 			Adress adress, boolean activated) {
 		super(phoneNumber, name, username, mail, password, adress, activated);
-		//this.listOfMeal = listOfMeal
+		this.listOfMeal = new ArrayList<Meal>();
+		this.listOfDish = new ArrayList<Dish>();
 	}
 	
 	
-	public void addMeal(){
+	/** SETTERS**/
+	
+	
+	
+	
+	public void addMeal(Meal m){
+		boolean isalready = false;
+		for (Meal meal : this.listOfMeal) {
+			if(meal.equals(m)){
+				System.out.println("You already have this meal in our menu");
+				isalready = true;
+			}
+			}
+		if(isalready == false){
+			this.listOfMeal.add(m);
+		}
+		}
 		
+	
+	
+	
+	@Override
+	public String toString() {
+		return "Restaurant [listOfMeal=" + listOfMeal + ", listOfDish=" + listOfDish + "]";
+	}
+
+
+	public ArrayList<Meal> getListOfMeal() {
+		return listOfMeal;
+	}
+
+
+	public ArrayList<Dish> getListOfDish() {
+		return listOfDish;
+	}
+
+
+	public void addDish(Dish d){
+		boolean isalready = false;
+		for (Dish dish : this.listOfDish) {
+			if(dish.equals(d)){
+				System.out.println("You already have this dish in our menu");
+				isalready = true;
+			}
+		}
+		if(isalready == false){
+			this.listOfDish.add(d);
+
+		}
 	}
 	
-	public void removeItem(){
+	
+	public void removeMeal(Meal m){
+		this.listOfMeal.remove(m);
 		
 	}
+	
+	public void removeDish(Dish d){
+		this.listOfDish.remove(d);
+	}
 
 }
-- 
GitLab