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

my work

parent 8ba8b2c1
Branches
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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));
}
}
......@@ -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;
}
}
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;
}
}
......@@ -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;
}
}
......@@ -18,6 +18,27 @@ 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(){
......
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){
}
......
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>();
}
/** 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);
}
//this.listOfMeal = listOfMeal
}
public void addMeal(){
@Override
public String toString() {
return "Restaurant [listOfMeal=" + listOfMeal + ", listOfDish=" + listOfDish + "]";
}
public void removeItem(){
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 removeDish(Dish d){
this.listOfDish.remove(d);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment