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

modif

parent 0088bc1d
No related branches found
No related tags found
No related merge requests found
Showing
with 3081 additions and 17 deletions
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/>
This diff is collapsed.
model.uml 0 → 100644
This diff is collapsed.
...@@ -13,8 +13,23 @@ public class BasicFidelityCard extends FidelityCard implements VisitableCard { ...@@ -13,8 +13,23 @@ public class BasicFidelityCard extends FidelityCard implements VisitableCard {
} }
@Override @Override
public long accept() { public long acceptPoint() {
// TODO Auto-generated method stub
return 0; return 0;
} }
@Override
public double acceptPercentage() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String toString() {
return "Type of Card : Basic \n"
+ "id : " + id;
}
} }
...@@ -5,9 +5,9 @@ public class LotteryFidelityCard extends FidelityCard implements VisitableCard { ...@@ -5,9 +5,9 @@ public class LotteryFidelityCard extends FidelityCard implements VisitableCard {
private double percentage; private double percentage;
public LotteryFidelityCard(double percentage) { public LotteryFidelityCard() {
super(); super();
this.percentage = percentage; this.percentage = 0.05;
} }
...@@ -18,10 +18,19 @@ public class LotteryFidelityCard extends FidelityCard implements VisitableCard { ...@@ -18,10 +18,19 @@ public class LotteryFidelityCard extends FidelityCard implements VisitableCard {
return "Lottery"; return "Lottery";
} }
public boolean getReduction(){
boolean chance = false;
double tirage = Math.random();
if(tirage < this.percentage){
chance = true;
}
return chance;
}
@Override
public long accept() { public double getPercentage() {
return 0; return percentage;
} }
...@@ -29,4 +38,28 @@ public class LotteryFidelityCard extends FidelityCard implements VisitableCard { ...@@ -29,4 +38,28 @@ public class LotteryFidelityCard extends FidelityCard implements VisitableCard {
this.percentage = percentage; this.percentage = percentage;
} }
@Override
public long acceptPoint() {
// TODO Auto-generated method stub
return 0;
}
@Override
public double acceptPercentage() {
// TODO Auto-generated method stub
return this.percentage;
}
@Override
public String toString() {
return "Type of Card : Lottery \n"
+ "percentage : " + percentage + "\n"
+ " id : " + id;
}
} }
...@@ -18,7 +18,7 @@ public class PointFidelityCard extends FidelityCard implements VisitableCard { ...@@ -18,7 +18,7 @@ public class PointFidelityCard extends FidelityCard implements VisitableCard {
} }
@Override @Override
public long accept() { public long acceptPoint() {
return this.nbOfPoint; return this.nbOfPoint;
} }
...@@ -32,6 +32,22 @@ public class PointFidelityCard extends FidelityCard implements VisitableCard { ...@@ -32,6 +32,22 @@ public class PointFidelityCard extends FidelityCard implements VisitableCard {
} }
@Override
public double acceptPercentage() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String toString() {
return "Type of Card : Point \n"
+ "nbOfPoint : " + nbOfPoint + "\n"
+ " id : " + id;
}
} }
...@@ -2,6 +2,7 @@ package Cards; ...@@ -2,6 +2,7 @@ package Cards;
public interface VisitableCard { public interface VisitableCard {
public abstract long accept(); public abstract long acceptPoint();
public abstract double acceptPercentage();
} }
...@@ -2,6 +2,7 @@ package Cards; ...@@ -2,6 +2,7 @@ package Cards;
public interface VisiterCard { public interface VisiterCard {
public abstract long visit(VisitableCard card); public abstract long visit(PointFidelityCard card);
public abstract double visit(LotteryFidelityCard card);
} }
...@@ -4,15 +4,39 @@ import java.util.ArrayList; ...@@ -4,15 +4,39 @@ import java.util.ArrayList;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import Commands.Login; import Commands.Login;
import Commands.AddDishRestaurantMenu;
import Commands.AddDishToMeal;
import Commands.AddItemToOrder;
import Commands.AssociateCard;
import Commands.CreateMeal;
import Commands.CreateOrder;
import Commands.EndOrder;
import Commands.Help; import Commands.Help;
import Commands.Logout; import Commands.Logout;
import Commands.OffDuty;
import Commands.OnDuty;
import Commands.RegisterCourier; import Commands.RegisterCourier;
import Commands.RegisterCustomer; import Commands.RegisterCustomer;
import Commands.RegisterRestaurant; import Commands.RegisterRestaurant;
import Commands.RemoveSpecialOffer;
import Commands.RenameMeal;
import Commands.RunTest;
import Commands.SetDeliveryPolicy;
import Commands.SetProfitPolicy;
import Commands.SetSpecialOffer;
import Commands.ShowCourier;
import Commands.ShowCustomer; import Commands.ShowCustomer;
import Commands.ShowMeal;
import Commands.ShowMenuItem;
import Commands.ShowProfitBetween;
import Commands.ShowRestaurantTop; import Commands.ShowRestaurantTop;
import Commands.ShowTotalProfit;
import Core.ActiveUserContext; import Core.ActiveUserContext;
import Core.MyFoodora; import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import Exception.ExceptionUnknownStartegyType;
import Exception.ExceptionUnknownTypeOfUser;
public class Clui { public class Clui {
...@@ -25,15 +49,35 @@ public class Clui { ...@@ -25,15 +49,35 @@ public class Clui {
super(); super();
this.foodora = _foodora; this.foodora = _foodora;
this.activeUser = _activeUser; this.activeUser = _activeUser;
this.listOfCommand.add(new Login()); this.listOfCommand.add(new AddDishRestaurantMenu());
this.listOfCommand.add(new AddDishToMeal());
this.listOfCommand.add(new RegisterCourier());
this.listOfCommand.add(new AddItemToOrder());
this.listOfCommand.add(new AssociateCard());
this.listOfCommand.add(new CreateMeal());
this.listOfCommand.add(new CreateOrder());
this.listOfCommand.add(new EndOrder());
this.listOfCommand.add(new Help()); this.listOfCommand.add(new Help());
this.listOfCommand.add(new Login());
this.listOfCommand.add(new Logout()); this.listOfCommand.add(new Logout());
this.listOfCommand.add(new RegisterRestaurant()); this.listOfCommand.add(new OffDuty());
this.listOfCommand.add(new RegisterCustomer()); this.listOfCommand.add(new OnDuty());
this.listOfCommand.add(new RegisterCourier()); this.listOfCommand.add(new RegisterCourier());
this.listOfCommand.add(new RegisterCustomer());
this.listOfCommand.add(new RegisterRestaurant());
this.listOfCommand.add(new RemoveSpecialOffer());
this.listOfCommand.add(new RenameMeal());
this.listOfCommand.add(new RunTest());
this.listOfCommand.add(new SetDeliveryPolicy());
this.listOfCommand.add(new SetProfitPolicy());
this.listOfCommand.add(new SetSpecialOffer());
this.listOfCommand.add(new ShowCourier());
this.listOfCommand.add(new ShowCustomer()); this.listOfCommand.add(new ShowCustomer());
this.listOfCommand.add(new ShowMeal());
this.listOfCommand.add(new ShowMenuItem());
this.listOfCommand.add(new ShowProfitBetween());
this.listOfCommand.add(new ShowRestaurantTop()); this.listOfCommand.add(new ShowRestaurantTop());
this.listOfCommand.add(new ShowTotalProfit());
} }
public Command getCommand(String commandName) { public Command getCommand(String commandName) {
...@@ -44,7 +88,7 @@ public class Clui { ...@@ -44,7 +88,7 @@ public class Clui {
return null; return null;
} }
public void executeCommand(String command){ public void executeCommand(String command) throws ExceptionUnknownMealType, NumberFormatException, ExceptionUnknownDishType, ExceptionUnknownStartegyType, ExceptionUnknownTypeOfUser{
StringTokenizer st = new StringTokenizer(command); StringTokenizer st = new StringTokenizer(command);
String commandName = st.nextToken(); String commandName = st.nextToken();
ArrayList<String> arguments = new ArrayList<String>(); ArrayList<String> arguments = new ArrayList<String>();
...@@ -72,7 +116,7 @@ public class Clui { ...@@ -72,7 +116,7 @@ public class Clui {
} }
} }
public void launchClui() throws errorWrongNumberOfParams, errorWrongFormatValue{ public void launchClui() throws errorWrongNumberOfParams, errorWrongFormatValue, ExceptionUnknownMealType, NumberFormatException, ExceptionUnknownDishType, ExceptionUnknownStartegyType, ExceptionUnknownTypeOfUser{
System.out.println("Welcome to MyFoodora system, type help <> in order to have all the possible commands"); System.out.println("Welcome to MyFoodora system, type help <> in order to have all the possible commands");
while(true){ while(true){
String command = Input.string("===================\n" String command = Input.string("===================\n"
......
...@@ -4,6 +4,10 @@ import java.util.ArrayList; ...@@ -4,6 +4,10 @@ import java.util.ArrayList;
import Core.ActiveUserContext; import Core.ActiveUserContext;
import Core.MyFoodora; import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import Exception.ExceptionUnknownStartegyType;
import Exception.ExceptionUnknownTypeOfUser;
public abstract class Command { public abstract class Command {
private String commandName; private String commandName;
...@@ -15,7 +19,7 @@ public abstract class Command { ...@@ -15,7 +19,7 @@ public abstract class Command {
} }
public boolean isOneWanted(String firstToken){ public boolean isOneWanted(String firstToken){
if(firstToken.equals(commandName)) if(firstToken.toLowerCase().equals(commandName.toLowerCase()))
return true; return true;
return false; return false;
} }
...@@ -33,6 +37,6 @@ public abstract class Command { ...@@ -33,6 +37,6 @@ public abstract class Command {
return true; return true;
} }
public abstract void execute(ArrayList<String> arguments, MyFoodora foodora, ActiveUserContext activeUser); public abstract void execute(ArrayList<String> arguments, MyFoodora foodora, ActiveUserContext activeUser) throws ExceptionUnknownMealType, NumberFormatException, ExceptionUnknownDishType, ExceptionUnknownStartegyType, ExceptionUnknownTypeOfUser;
} }
package Commands;
import java.util.ArrayList;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import Item.Dish;
import Others.Adress;
import User.Manager;
import User.Restaurant;
import User.User;
public class AddDishRestaurantMenu extends Command {
public AddDishRestaurantMenu() {
super("addDishRestaurantMenu",
new Token[]{new Token(Token.TypeToken.integer,"dishName")
,new Token(Token.TypeToken.str,"dishCategory")
,new Token(Token.TypeToken.str,"foodCategory")
,new Token(Token.TypeToken.decimal,"unitPrice")}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws NumberFormatException, ExceptionUnknownDishType {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Restaurant){
Restaurant r = (Restaurant) activeUser.getUser();
r.addDish(arg.get(1), arg.get(0), arg.get(2), Double.parseDouble(arg.get(3)));
System.out.println("Customer added : " + foodora.getUserByName(arg.get(1), arg.get(2)));
}else{
System.out.println("You need to be a logged Restaurant in order to access this function");
}
}
}
package Commands;
import java.util.ArrayList;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import User.Restaurant;
public class AddDishToMeal extends Command {
public AddDishToMeal() {
super("addDishToMeal",
new Token[]{new Token(Token.TypeToken.str,"dishName")
,new Token(Token.TypeToken.str,"mealName")}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws NumberFormatException {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Restaurant){
Restaurant r = (Restaurant) activeUser.getUser();
r.addDishToMeal(r.getDishByName(arg.get(0)),r.getMealByName(arg.get(1)));
System.out.println("You added "+arg.get(0)+" to "+arg.get(1));
}else{
System.out.println("You need to be a logged Restaurant in order to access this function");
}
}
}
package Commands;
import java.util.ArrayList;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import Order.Order;
import User.Customer;
import User.Restaurant;
public class AddItemToOrder extends Command {
public AddItemToOrder() {
super("addItemToOrder",
new Token[]{new Token(Token.TypeToken.str,"orderName"),
new Token(Token.TypeToken.str,"itemName")}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws NumberFormatException {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Customer){
Customer c = (Customer) activeUser.getUser();
Order o = c.getOrderByName(arg.get(0));
o.addItemByName(arg.get(1));
System.out.println(arg.get(1) + " added in "+arg.get(0)+".");
}else{
System.out.println("You need to be a logged Customer in order to access this function");
}
}
}
package Commands;
import java.util.ArrayList;
import Cards.FidelityCard;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import Exception.ExceptionUnknownStartegyType;
import User.Customer;
import User.Manager;
public class AssociateCard extends Command {
public AssociateCard() {
super("associateCard",
new Token[]{new Token(Token.TypeToken.str,"customerUsername"),
new Token(Token.TypeToken.str,"cardType")}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws NumberFormatException, ExceptionUnknownStartegyType {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Manager){
Manager m = (Manager) activeUser.getUser();
Customer c = (Customer) foodora.getUserByUsername(arg.get(0));
c.registerFidelityPlan(arg.get(1));
}else{
System.out.println("You need to be a logged Manager in order to access this function");
}
}
}
package Commands;
import java.util.ArrayList;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import Exception.ExceptionUnknownMealType;
import User.Restaurant;
public class CreateMeal extends Command {
public CreateMeal() {
super("createMeal",
new Token[]{new Token(Token.TypeToken.str,"nameOfTheMeal"),
new Token(Token.TypeToken.str,"typeOfMeal")
}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws ExceptionUnknownMealType {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Restaurant){
Restaurant r = (Restaurant) activeUser.getUser();
r.createMeal(arg.get(0), arg.get(1));
System.out.println("Meal added : "+arg.get(0));
}else{
System.out.println("You need to be a logged Restaurant in order to access this function");
}
}
}
package Commands;
import java.util.ArrayList;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import User.Customer;
import User.Restaurant;
public class CreateOrder extends Command {
public CreateOrder() {
super("createOrder",
new Token[]{new Token(Token.TypeToken.str,"restaurantName"),
new Token(Token.TypeToken.str,"orderName")}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws NumberFormatException {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Customer){
Customer c = (Customer) activeUser.getUser();
Restaurant r = (Restaurant) foodora.getUserByUsername(arg.get(0));
c.createOrder(arg.get(1), r);
System.out.println(arg.get(1) + " created for "+arg.get(0)+".");
}else{
System.out.println("You need to be a logged Customer in order to access this function");
}
}
}
package Commands;
import java.util.ArrayList;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import Order.Order;
import User.Customer;
public class EndOrder extends Command {
public EndOrder() {
super("endOrder",
new Token[]{new Token(Token.TypeToken.str,"orderName"),
new Token(Token.TypeToken.date,"orderDate")}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws NumberFormatException {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Customer){
Customer c = (Customer) activeUser.getUser();
c.getOrderByName(arg.get(0)).finalize();
System.out.println(arg.get(1) + " finalized the "+arg.get(0)+".");
}else{
System.out.println("You need to be a logged Customer in order to access this function");
}
}
}
\ No newline at end of file
package Commands;
import java.util.ArrayList;
import Cli.Command;
import Cli.Token;
import Core.ActiveUserContext;
import Core.MyFoodora;
import Exception.ExceptionUnknownDishType;
import Exception.ExceptionUnknownMealType;
import Order.Order;
import User.Courier;
import User.Manager;
public class FindDeliverer extends Command {
public FindDeliverer() {
super("findDeliverer",
new Token[]{new Token(Token.TypeToken.str,"orderName")}
);
// TODO Auto-generated constructor stub
}
@Override
public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) throws NumberFormatException {
// TODO Auto-generated method stub
if(activeUser.getUser() instanceof Manager){
Manager m = (Manager) activeUser.getUser();
Order o = foodora.getPendingOrderByName(arg.get(0));
Courier c = foodora.getContextDeliveryPolicy().getStrategy().chooseCourier(o.getRestaurantAttached(), foodora.getCustomerByOrder(o), foodora.getListCourier().getList());
System.out.println(c.toString());
}else{
System.out.println("You need to be a logged Manager in order to access this function");
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment