diff --git a/src/Cli/Confirm.java b/src/Cli/Confirm.java index 4a3448ccce6042574337b7fe87543dc90c0ffc50..abd707b7a1023e4c16f3141cc15bd068da9597c1 100644 --- a/src/Cli/Confirm.java +++ b/src/Cli/Confirm.java @@ -3,13 +3,11 @@ 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/Core/MyFoodora.java b/src/Core/MyFoodora.java index f56012b485a65041b4c794323bf0c28466e55f29..7c8445070abf191d84d3a8c307fd425c15715146 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/Item/Dish.java b/src/Item/Dish.java index ac68bfef911fd19356ba822c9553ad15edc054dd..5fa2635b3c591f8c1d2b58fde07162d20c067610 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 e1da97d69b5cf8f37e3a058ce4315e134c5d0052..c9ed7b51268e9c16ec9d1d19e9249d41fe7bccbb 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/Meal.java b/src/Item/Meal.java index c6741ad86ef6a35251de06cb04f1b86c413c5570..9198b01898cf8aee97275b924742707cff08fb85 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/Order/Order.java b/src/Order/Order.java index f35b236ed9b925abbb4187929bf4b7615f45ec97..d4717f95226f02414bdc175d9356f572430b01d8 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; } diff --git a/src/User/Customer.java b/src/User/Customer.java index 017e73391a11938ae02cc97598a69b2dfd473ec4..4ed3b45b885604dc3d635e6156203a151291ea81 100644 --- a/src/User/Customer.java +++ b/src/User/Customer.java @@ -1,8 +1,5 @@ package User; -import java.util.Scanner; -import Cli.Confirm; - import Cards.BasicFidelityCard; import Cards.FidelityCard; import Cards.LotteryFidelityCard; @@ -13,10 +10,6 @@ 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 { @@ -45,72 +38,7 @@ public class Customer extends HumanUser implements VisiterCard { return "Customer [spamAgree=" + spamAgree + ", historique=" + historique + ", card=" + card + "]"; } - 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?")){ - - } + public void placeOrder(Order order, Restaurant restaurant){ } diff --git a/src/User/Restaurant.java b/src/User/Restaurant.java index 2e6815200d304f7ca3d6db6a5133ea490677d2e8..971ba54ceed0342043cd8f7cfc1054c0c77e2da6 100644 --- a/src/User/Restaurant.java +++ b/src/User/Restaurant.java @@ -1,87 +1,24 @@ package User; -import java.util.ArrayList; - -import Item.Dish; -import Item.Meal; import Others.Adress; public class Restaurant extends MoralUser { - - - ArrayList<Meal> listOfMeal; - ArrayList<Dish> listOfDish; - - /** CONSTRUCTOR **/ + //ArrayList<Meal> listOfMeal; 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 = new ArrayList<Meal>(); - this.listOfDish = new ArrayList<Dish>(); + //this.listOfMeal = listOfMeal } - /** 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); - } - } + public void addMeal(){ - - - - @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 removeMeal(Meal m){ - this.listOfMeal.remove(m); + public void removeItem(){ } - - public void removeDish(Dish d){ - this.listOfDish.remove(d); - } }