diff --git a/src/Cards/FidelityCard.java b/src/Cards/FidelityCard.java index 6f27e524027e78149d078a642b72930f7a7d7335..c52064bd4bd67f8a22b868fff6ef578ef4c09d40 100644 --- a/src/Cards/FidelityCard.java +++ b/src/Cards/FidelityCard.java @@ -7,6 +7,7 @@ public abstract class FidelityCard implements VisitableCard { protected long id; + public FidelityCard (){ IDCard idCard = IDCard.getInstance(); this.id = idCard.getNextSerialNumber(); diff --git a/src/Cards/PointFidelityCard.java b/src/Cards/PointFidelityCard.java index 66471c902b406d072146fa57810553087c215e7a..9b0ce3d532ce22696efc22ea4ecbb9aa7c39a1a2 100644 --- a/src/Cards/PointFidelityCard.java +++ b/src/Cards/PointFidelityCard.java @@ -8,6 +8,7 @@ public class PointFidelityCard extends FidelityCard implements VisitableCard { public PointFidelityCard() { super(); this.nbOfPoint =0; + } @Override @@ -22,4 +23,15 @@ public class PointFidelityCard extends FidelityCard implements VisitableCard { } + public long getNbOfPoint() { + return nbOfPoint; + } + + public void setNbOfPoint(long nbOfPoint) { + this.nbOfPoint = nbOfPoint; + } + + + + } diff --git a/src/Cli/Clui.java b/src/Cli/Clui.java index 42b7c18623863e5766799b557ae7ece1074d2fae..e0772955031aba65cdd3964ea0b0d9b6f4dff865 100644 --- a/src/Cli/Clui.java +++ b/src/Cli/Clui.java @@ -1,57 +1,84 @@ package Cli; import java.util.ArrayList; -import java.util.Scanner; import java.util.StringTokenizer; +import Commands.Login; +import Commands.Help; +import Commands.Logout; +import Commands.RegisterCourier; +import Commands.RegisterCustomer; +import Commands.RegisterRestaurant; +import Commands.ShowCustomer; +import Commands.ShowRestaurantTop; +import Core.ActiveUserContext; import Core.MyFoodora; public class Clui { private MyFoodora foodora; - private static ArrayList<String> listOfCommand = new ArrayList<String>() {{ add("login"); add("nom2"); add("nom3"); }}; + private ActiveUserContext activeUser; + private ArrayList<Command> listOfCommand = new ArrayList<Command>(); - public Clui(MyFoodora foodora) { + public Clui(MyFoodora _foodora, ActiveUserContext _activeUser) { super(); - this.foodora = foodora; - this.listOfCommand = listOfCommand; + this.foodora = _foodora; + this.activeUser = _activeUser; + this.listOfCommand.add(new Login()); + this.listOfCommand.add(new Help()); + this.listOfCommand.add(new Logout()); + this.listOfCommand.add(new RegisterRestaurant()); + this.listOfCommand.add(new RegisterCustomer()); + this.listOfCommand.add(new RegisterCourier()); + + this.listOfCommand.add(new ShowCustomer()); + this.listOfCommand.add(new ShowRestaurantTop()); } - public static void main(String[] args) { - boolean dontStop = true; - System.out.println("Welcome to MyFoodora system, type help <> in order to have all the possible commands"); - String command = Input.string("type your command") ; + public Command getCommand(String commandName) { + for(Command c : this.listOfCommand){ + if(c.isOneWanted(commandName)) + return c; + } + return null; + } + + public void executeCommand(String command){ StringTokenizer st = new StringTokenizer(command); String commandName = st.nextToken(); ArrayList<String> arguments = new ArrayList<String>(); while (st.hasMoreTokens()) { arguments.add(st.nextToken()); } - boolean isIn = false; - for (String string : listOfCommand) { - if(commandName == string){ - isIn = true; - break; + + Command commandAsked; + commandAsked = getCommand(commandName); + if(commandAsked != null){ + try{ + if(commandAsked.isGoodArgument(arguments)){ + commandAsked.execute(arguments, foodora, activeUser); + }else{ + System.out.println("Error in the arguments."); + } + }catch (errorWrongNumberOfParams ex) { + System.out.println(ex); } - - } - if (isIn = false){ - System.out.println("this command is not possible"); - } - else{ - if(commandName == "login"){ - + catch (errorWrongFormatValue ex) { + System.out.println(ex); } + }else{ + System.out.println("Unknown command."); } - - - } - - public void login(ArrayList<String> arguments){ - - - + + public void launchClui() throws errorWrongNumberOfParams, errorWrongFormatValue{ + System.out.println("Welcome to MyFoodora system, type help <> in order to have all the possible commands"); + while(true){ + String command = Input.string("===================\n" + + "Type your command : "); + executeCommand(command); + } } + } diff --git a/src/Cli/Command.java b/src/Cli/Command.java index 00b84f6a1f0bd39993080e20e5a1a5254c331a46..ac36c5f09e1927fa208126e537d3702065dc4af6 100644 --- a/src/Cli/Command.java +++ b/src/Cli/Command.java @@ -2,37 +2,28 @@ package Cli; import java.util.ArrayList; -import User.User; +import Core.ActiveUserContext; +import Core.MyFoodora; public abstract class Command { private String commandName; private Token [] listOfArgs; - private User [] typeOfInstanceAllowed; - public Command(String _commandName, Token [] _listOfArgs, User [] _typeOfInstanceAllowed){ + public Command(String _commandName, Token [] _listOfArgs){ commandName = _commandName; listOfArgs = _listOfArgs; - typeOfInstanceAllowed = _typeOfInstanceAllowed; } public boolean isOneWanted(String firstToken){ - if(firstToken == commandName) + if(firstToken.equals(commandName)) return true; return false; } - public boolean isGoodArgument(ArrayList<String> arguments, User typeOfUser){ + public boolean isGoodArgument(ArrayList<String> arguments) throws errorWrongNumberOfParams,errorWrongFormatValue{ if(arguments.size() != listOfArgs.length){ - return false; // devrait throw une erreur disant que c'est pas le bon nombre de param�tre. + throw new errorWrongNumberOfParams("Error : "+Integer.toString(arguments.size())+" parameter insteed of "+Integer.toString(listOfArgs.length)); } - boolean goodUserType=false; - for (User typeUser : typeOfInstanceAllowed){ - if(typeUser.getClass() == typeOfUser.getClass()){ - goodUserType=true; - } - } - if(!goodUserType) - return false; // devrait throw une erreur int i = 0; for (String arg : arguments) { listOfArgs[i].isTockenCorrect(arg); // throw une erreur, faut la catch au dessus ! @@ -42,6 +33,6 @@ public abstract class Command { return true; } - public abstract String execute(); + public abstract void execute(ArrayList<String> arguments, MyFoodora foodora, ActiveUserContext activeUser); } diff --git a/src/Cli/Confirm.java b/src/Cli/Confirm.java index 4a3448ccce6042574337b7fe87543dc90c0ffc50..bfd33689e1d59fdcc4f54af3625235bbc0201413 100644 --- a/src/Cli/Confirm.java +++ b/src/Cli/Confirm.java @@ -9,7 +9,6 @@ public class Confirm { 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 index 8cfdcb6dc2ad8a54c336b30cc0d0f2ccbeb77621..e5486ab289cde60b4771c4c17e5ed52487c63e5e 100644 --- a/src/Cli/Input.java +++ b/src/Cli/Input.java @@ -9,8 +9,8 @@ public class Input { Scanner reader = new Scanner(System.in); System.out.println(question); //System.out.println("Type the name"); - String string = reader.nextLine(); - reader.close(); + String string = ""; + string = reader.nextLine(); return string; } diff --git a/src/Cli/Token.java b/src/Cli/Token.java index 66b6f4e5d38237cf69d2dc904bd854a16535374c..f0d81608d86e7b021d20cd29b3889e1da44e79ba 100644 --- a/src/Cli/Token.java +++ b/src/Cli/Token.java @@ -16,7 +16,7 @@ public class Token { if(isTockenCorrect(_value)){ value = _value; }else{ - throw new errorWrongFormatValue("Format de "+name+" incorrect !"); + throw new errorWrongFormatValue("Incorrect format for "+name+" arg."); /* si incorrect, throw une erreur qui doit �tre catch par la fonction au dessus (et on doit annuler la commande */ } @@ -29,11 +29,17 @@ public class Token { public boolean isTockenCorrect(String _value){ switch(typeOfToken){ case date: + if(_value.matches("\\d{2}/\\d{2}/\\d{4}")) + return true; break; case integer: if(_value.matches("-?\\d+")) return true; break; + case position: + if(_value.matches("-?\\d+(\\.\\d+)\\,\\d+(\\.\\d+)?")) + return true; + break; case decimal: if(_value.matches("-?\\d+(\\.\\d+)?")) return true; @@ -44,7 +50,7 @@ public class Token { return false; } - static enum TypeToken{ - date,str,integer,decimal + public static enum TypeToken{ + date,str,integer,decimal,position } } diff --git a/src/Cli/errorWrongNumberOfParams.java b/src/Cli/errorWrongNumberOfParams.java new file mode 100644 index 0000000000000000000000000000000000000000..4c18d3c529389bb18e63aa88528dbd8132266ab7 --- /dev/null +++ b/src/Cli/errorWrongNumberOfParams.java @@ -0,0 +1,34 @@ +package Cli; + +public class errorWrongNumberOfParams extends Exception { + + /** + * + */ + private static final long serialVersionUID = 3780895191640653344L; + + public errorWrongNumberOfParams() { + // TODO Auto-generated constructor stub + } + + public errorWrongNumberOfParams(String arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public errorWrongNumberOfParams(Throwable arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public errorWrongNumberOfParams(String arg0, Throwable arg1) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + public errorWrongNumberOfParams(String arg0, Throwable arg1, boolean arg2, boolean arg3) { + super(arg0, arg1, arg2, arg3); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/Cli/errorWrongTypeOfUser.java b/src/Cli/errorWrongTypeOfUser.java new file mode 100644 index 0000000000000000000000000000000000000000..b671be87f8f2324488a98d11df50b4e07694c802 --- /dev/null +++ b/src/Cli/errorWrongTypeOfUser.java @@ -0,0 +1,35 @@ +package Cli; + +public class errorWrongTypeOfUser extends Exception { + + /** + * + */ + private static final long serialVersionUID = 7904486798144733615L; + + public errorWrongTypeOfUser() { + // TODO Auto-generated constructor stub + } + + public errorWrongTypeOfUser(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public errorWrongTypeOfUser(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + public errorWrongTypeOfUser(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public errorWrongTypeOfUser(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/Commands/Help.java b/src/Commands/Help.java new file mode 100644 index 0000000000000000000000000000000000000000..e4f7bc494fa9b381ca0940a9d850493ddcf589ad --- /dev/null +++ b/src/Commands/Help.java @@ -0,0 +1,53 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; + +public class Help extends Command { + + public Help() { + super("help", + new Token[]{} + ); + // TODO Auto-generated constructor stub + } + + @Override + public void execute(ArrayList<String> arguments, MyFoodora foodora, ActiveUserContext activeUser) { + System.out.println("Liste des commandes disponibles : \n" + + "login <username> <password> : to allow a user to perform the login (remark: aMyfoodora manager user with username: ceo and password:123456789 is assumedto exist)\n" + + "logout <> : to allow the currently logged on user to log off\n" + + "registerRestaurant <name> <address> <username> <password> : for the cur-rently logged on manager to add a restaurant of given name, address (i.e. addressshould be a bi-dimensional co-ordinate), username and password to the system.\n" + + "registerCustomer <firstName> <lastName> <username> <address> <password>: for the currently logged on manager to add a client to the system\n" + + "registerCourier <firstName> <lastName> <username> <position> <password>: for the currently logged on manager to add a courier to the system (by default eachnewly registered courier is on-duty).\n" + + "addDishRestauarantMenu <dishName> <dishCategory> <foodCategory> <unitPrice>: for the currently logged on restaurant to add a dish with given name, given cat-egory (starter,main,dessert), food type (standard,vegetarian, gluten-free) and priceto the menu of a restaurant with given name (this command can be executed by arestaurant-user only)\n" + + "createMeal <mealName> : for the currently logged on restaurant to create a mealwith a given name\n" + + "addDish2Meal <dishName> <mealName> : for the currently logged on restaurant toadd a dish to a meal\n" + + "showMeal <mealName> : for the currently logged on restaurant to show the dishesin a meal with given name\n" + + "saveMeal <mealName> : for the currently logged on restaurant to save a meal withgiven name\n" + + "setSpecialOffer <mealName> : for the currently logged on restaurant to add ameal in meal-of-the-week special oer\n" + + "removeFromSpecialOffer <mealName> : for the currently logged on restaurant toreset a special offer\n" + + "createOrder <restaurantName> <orderName> : for the currently logged on cus-tomer to create an order from a given restaurant\n" + + "addItem2Order <orderName> <itemName> : for the currently logged on customerto add an item (either a menu item or a meal-deal) to an existing order\n" + + "endOrder <orderName> < date> : for the currently logged on customer to finalise an order at a given date and pay it\n" + + "onDuty <username> : for the currently logged on courier to set his state as on-duty\n" + + "offDuty <username> : for the currently logged on courier to set his state as off-duty\n" + + "findDeliverer <orderName> : for the currently logged on restaurant to allocate anorder to a deliverer by application of the current delivery policy (remark: this is justan extra facility of the CLUI, that will allow us to test whether deliverer allocationworks properly. The actual allocation of a deliverer should be automatically triggeredby the system on completion of an order by a customer).\n" + + "setDeliveryPolicy <delPolicyName> : for the currently logged on myFoodoramanager to set the delivery policy of the system to that passed as argument\n" + + "setProfitPolicy <ProfitPolicyName> : for the currently logged on myFoodoramanager set the prot policy of the system to that passed as argument\n" + + "associateCard <userName> <cardType> for the currently logged on myFoodoramanager to associate a delity card to a user with given namePage\n" + + "showCourierDeliveries <> for the currently logged on myFoodora manager to dis-play the list of couriers sorted in decreasing order w.r.t. the number of completeddeliveries\n" + + "showRestaurantTop <> for the currently logged on myFoodora manager to displaythe list of restaurant sorted in decreasing order w.r.t. the number of delivered orders\n" + + "showCustomers <> for the currently logged on myFoodora manager to display thelist of customers\n" + + "showMenuItem <restaurant-name> for the currently logged on myFoodora managerto display the menu of a given restaurant\n" + + "showTotalProfit<> for the currently logged on myFoodora manager to show thetotal profit of the system since creation\n" + + "showTotalProfit <startDate> <endDate> for the currently logged on myFoodoramanager to show the total prfit of the system within a time interval\n" + + "runTest <testScenario-file> for a generic user of the CLUI (no need to login)to execute the list of CLUI commands contained in the testScenario le passed asargument\n" + + "help <> for a generic user of the CLUI (no need to login) to display the list ofavailable CLUI commands (a command per line) with an indication of their syntax\n"); + } + +} diff --git a/src/Commands/Login.java b/src/Commands/Login.java new file mode 100644 index 0000000000000000000000000000000000000000..f276a64c0d145eb94807d5a1df2f2461c019294a --- /dev/null +++ b/src/Commands/Login.java @@ -0,0 +1,33 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; +import User.User; + + +public class Login extends Command { + + public Login() { + super("login", + new Token[]{new Token(Token.TypeToken.str,"username"),new Token(Token.TypeToken.str,"password")} + ); + // TODO Auto-generated constructor stub + } + + @Override + public void execute(ArrayList<String> args, MyFoodora foodora, ActiveUserContext activeUser) { + // TODO Auto-generated method stub + User user = foodora.getUserByLogin(args.get(0), args.get(1)); + if(user == null) + System.out.println("Wrong username and/or password"); + else{ + System.out.println("Hi "+user.getName() +" !"); + activeUser.setActiveUser(user); + } + } + +} diff --git a/src/Commands/Logout.java b/src/Commands/Logout.java new file mode 100644 index 0000000000000000000000000000000000000000..307014a093eb2f6a8dc2d25778cc190f1388a962 --- /dev/null +++ b/src/Commands/Logout.java @@ -0,0 +1,29 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; + +public class Logout extends Command { + + public Logout() { + super("logout", + new Token[]{} + ); + // TODO Auto-generated constructor stub + } + + @Override + public void execute(ArrayList<String> arguments, MyFoodora foodora, ActiveUserContext activeUser) { + if(activeUser.getUser()==null){ + System.out.println("Already disconnected."); + }else{ + activeUser.setActiveUser(null); + System.out.println("Bye !"); + } + } + +} diff --git a/src/Commands/RegisterCourier.java b/src/Commands/RegisterCourier.java new file mode 100644 index 0000000000000000000000000000000000000000..1e202d62dc41c60964db56f6bdc8cd7c5fc27972 --- /dev/null +++ b/src/Commands/RegisterCourier.java @@ -0,0 +1,41 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; +import Others.Adress; +import User.Manager; +import User.User; + +public class RegisterCourier extends Command { + + public RegisterCourier() { + super("registerCourier", + new Token[]{new Token(Token.TypeToken.integer,"tel") + ,new Token(Token.TypeToken.str,"name") + ,new Token(Token.TypeToken.str,"username") + ,new Token(Token.TypeToken.str,"mail") + ,new Token(Token.TypeToken.str,"password") + ,new Token(Token.TypeToken.position,"adress") + ,new Token(Token.TypeToken.date,"birthday")} + ); + // TODO Auto-generated constructor stub + } + + @Override + public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) { + // TODO Auto-generated method stub + if(activeUser.getUser() instanceof Manager){ + Manager m = (Manager) activeUser.getUser(); + // registerCourier 0123456789 resto1 resto1 mail password 0.01,0.02 22/03/1995 + m.addUser(Long.parseLong(arg.get(0)), arg.get(1), arg.get(2), arg.get(3), arg.get(4), Adress.fromStr(arg.get(5)), true, arg.get(6), "1", foodora, User.COURIER , "Human"); + System.out.println("Courier added : " + foodora.getUserByName(arg.get(1), arg.get(2))); + }else{ + System.out.println("You need to be a manager in order to access this function"); + } + } + +} diff --git a/src/Commands/RegisterCustomer.java b/src/Commands/RegisterCustomer.java new file mode 100644 index 0000000000000000000000000000000000000000..3bce9860c5437b4b8e17033d9817a54c7c4fea70 --- /dev/null +++ b/src/Commands/RegisterCustomer.java @@ -0,0 +1,41 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; +import Others.Adress; +import User.Manager; +import User.User; + +public class RegisterCustomer extends Command { + + public RegisterCustomer() { + super("registerCustomer", + new Token[]{new Token(Token.TypeToken.integer,"tel") + ,new Token(Token.TypeToken.str,"name") + ,new Token(Token.TypeToken.str,"username") + ,new Token(Token.TypeToken.str,"mail") + ,new Token(Token.TypeToken.str,"password") + ,new Token(Token.TypeToken.position,"adress") + ,new Token(Token.TypeToken.date,"birthday")} + ); + // TODO Auto-generated constructor stub + } + + @Override + public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) { + // TODO Auto-generated method stub + if(activeUser.getUser() instanceof Manager){ + Manager m = (Manager) activeUser.getUser(); + // registerRestaurant 0123456789 resto1 resto1 mail password 0.01,0.02 22/03/1995 + m.addUser(Long.parseLong(arg.get(0)), arg.get(1), arg.get(2), arg.get(3), arg.get(4), Adress.fromStr(arg.get(5)), true, arg.get(6), "1", foodora, User.CUSTOMER , "Human"); + System.out.println("Customer added : " + foodora.getUserByName(arg.get(1), arg.get(2))); + }else{ + System.out.println("You need to be a manager in order to access this function"); + } + } + +} diff --git a/src/Commands/RegisterRestaurant.java b/src/Commands/RegisterRestaurant.java new file mode 100644 index 0000000000000000000000000000000000000000..cff697fed2b932afbe531ffcf41a8d20a765fc48 --- /dev/null +++ b/src/Commands/RegisterRestaurant.java @@ -0,0 +1,41 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; +import Others.Adress; +import User.Manager; +import User.Restaurant; +import User.User; + +public class RegisterRestaurant extends Command { + + public RegisterRestaurant() { + super("registerRestaurant", + new Token[]{new Token(Token.TypeToken.integer,"tel") + ,new Token(Token.TypeToken.str,"name") + ,new Token(Token.TypeToken.str,"username") + ,new Token(Token.TypeToken.str,"mail") + ,new Token(Token.TypeToken.str,"password") + ,new Token(Token.TypeToken.position,"adress")} + ); + // TODO Auto-generated constructor stub + } + + @Override + public void execute(ArrayList<String> arg, MyFoodora foodora, ActiveUserContext activeUser) { + // TODO Auto-generated method stub + if(activeUser.getUser() instanceof Manager){ + Manager m = (Manager) activeUser.getUser(); + // registerRestaurant 0123456789 resto1 resto1 mail password 0.01,0.02 + m.addUser(Long.parseLong(arg.get(0)), arg.get(1), arg.get(2), arg.get(3), arg.get(4), Adress.fromStr(arg.get(5)), true, "1", "1", foodora, User.RESTAURANT , "Moral"); + System.out.println("Restaurant added : " + foodora.getUserByName(arg.get(1), arg.get(2))); + }else{ + System.out.println("You need to be a manager in order to access this function"); + } + } + +} diff --git a/src/Commands/ShowCustomer.java b/src/Commands/ShowCustomer.java new file mode 100644 index 0000000000000000000000000000000000000000..4f6a131a6f73adf1c49acf0bf2acd787d248f5c3 --- /dev/null +++ b/src/Commands/ShowCustomer.java @@ -0,0 +1,32 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; +import User.Manager; + +public class ShowCustomer extends Command { + + public ShowCustomer() { + super("showCustomers", new Token[]{}); + // TODO Auto-generated constructor stub + } + // + "showCustomers <> for the currently logged on myFoodora manager to display thelist of customers\n" + + @Override + public void execute(ArrayList<String> arguments, MyFoodora foodora, ActiveUserContext activeUser) { + if(activeUser.getUser() instanceof Manager){ + System.out.println(foodora.getListCustomer().getList().toString()); + } + else{ + System.out.println("You need to be a manager in order to access this function"); + } + + } + + + +} diff --git a/src/Commands/ShowRestaurantTop.java b/src/Commands/ShowRestaurantTop.java new file mode 100644 index 0000000000000000000000000000000000000000..7863bfaeee0c052368b9b63ec96fb6db1316ebe4 --- /dev/null +++ b/src/Commands/ShowRestaurantTop.java @@ -0,0 +1,50 @@ +package Commands; + +import java.util.ArrayList; + +import Cli.Command; +import Cli.Token; +import Core.ActiveUserContext; +import Core.MyFoodora; +import User.Manager; +import User.Restaurant; + +public class ShowRestaurantTop extends Command { + + public ShowRestaurantTop() { + super("showRestaurantTop", new Token[]{}); + // TODO Auto-generated constructor stub + } + + @Override + public void execute(ArrayList<String> arguments, MyFoodora foodora, ActiveUserContext activeUser) { + if(activeUser.getUser() instanceof Manager){ + ArrayList<Restaurant> sortListOfRestaurant = new ArrayList<Restaurant>(); + ArrayList<Restaurant> listOfRestaurant = foodora.getListRestaurant().getList(); + ArrayList<Restaurant> listToSort = new ArrayList<Restaurant>(); + for(Restaurant restaurant : listOfRestaurant){ + listToSort.add(restaurant); + } + while(listToSort.isEmpty() == false){ + long maxNbOfSell = 0; + Restaurant mostSeller = null; + for(Restaurant r : listToSort){ + if(r.getHistoricOrder().getListOrder().size() >= maxNbOfSell){ + mostSeller = r; + maxNbOfSell = r.getHistoricOrder().getListOrder().size(); + } + } + sortListOfRestaurant.add(mostSeller); + listToSort.remove(mostSeller); + } + + System.out.println(sortListOfRestaurant.toString()); + + } + else{ + System.out.println("You need to be a manager in order to access this function"); + } + + } + +} diff --git a/src/Core/ActiveUserContext.java b/src/Core/ActiveUserContext.java index ec5a8fa0673cfd093f9bbf3ffa68e19949c05bf4..2fab4152be88c621c9aadd8f440f5d938f6c4ec1 100644 --- a/src/Core/ActiveUserContext.java +++ b/src/Core/ActiveUserContext.java @@ -7,7 +7,8 @@ public class ActiveUserContext { User activeUser; public ActiveUserContext(MyFoodora foodora) { // TODO Auto-generated constructor stub - } + activeUser = null; + } public User getUser(){ return activeUser; } diff --git a/src/Core/ContextStrategy.java b/src/Core/ContextStrategy.java index bf082c8e3fe91a2315370c3cdce0f6bfed208944..921f9fe8384f8f95557bdf52fc9746eb6ac38cbf 100644 --- a/src/Core/ContextStrategy.java +++ b/src/Core/ContextStrategy.java @@ -4,6 +4,5 @@ import Exception.ExceptionUnknownStartegyType; public interface ContextStrategy { public abstract void setStrategy(String strategyName) throws ExceptionUnknownStartegyType; - public abstract void execute(MyFoodora myFoodora, double targetProfit); } diff --git a/src/Core/Main.java b/src/Core/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..16df4829c9cf751ee619fe2e3acf4fd4308efa46 --- /dev/null +++ b/src/Core/Main.java @@ -0,0 +1,58 @@ +package Core; + +import java.util.ArrayList; + +import Cli.Clui; +import Cli.errorWrongFormatValue; +import Cli.errorWrongNumberOfParams; +import Exception.ExceptionUnknownDishType; +import Exception.ExceptionUnknownMealType; +import Exception.ExceptionUnknownStartegyType; +import Item.Dish; +import Others.Adress; +import User.User; +import User.Customer; +import User.Manager; +import User.Restaurant; + + +public class Main { + + public Main() { + // TODO Auto-generated constructor stub + } + + public static void main(String[] args) throws ExceptionUnknownStartegyType, errorWrongNumberOfParams, errorWrongFormatValue, ExceptionUnknownDishType, ExceptionUnknownMealType { + // TODO Auto-generated method stub + MyFoodora foodora = new MyFoodora(); + ActiveUserContext activeUser = new ActiveUserContext(foodora); + foodora.setMarkupPercentage(0.05); + foodora.setServiceFee(3.0); + Clui clui = new Clui(foodora,activeUser); + + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + + foodora.addManager(manager); + foodora.addUser(manager); + + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"", "", foodora,User.RESTAURANT,"Moral"); + manager.addUser(045, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, User.CUSTOMER, "Human"); + + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + Customer custo1 = (Customer) foodora.getUserByName("henry", "henry"); + resto1.addDish("MainDish", "pat�", "glutenFree", 4.5); + resto1.createMeal("MyMeal", "HalfMeal"); + resto1.getMealByName("MyMeal").addDish(resto1.getDishByName("pat�")); + + custo1.createOrder("myOrder",resto1); + custo1.getOrderByName("myOrder").add(resto1.getDishByName("pat�")); + custo1.getOrderByName("myOrder").add(resto1.getMealByName("MyMeal")); + + clui.executeCommand("login jacquo 123456789"); + clui.executeCommand("registerRestaurant 0123456789 resto resto mail password 0.01,0.02"); + clui.executeCommand("registerCustomer 0123456789 custo custo mail password 0.01,0.02 22/03/1995"); + clui.executeCommand("registerCourier 0123456789 resto1 resto1 mail password 0.01,0.02 22/03/1995"); + clui.launchClui(); + } + +} diff --git a/src/Core/MyFoodora.java b/src/Core/MyFoodora.java index 8db5939589ff7d639b6ff206d135e875e15923ce..bee83964780571784eb9db9a319b637c98bb8e72 100644 --- a/src/Core/MyFoodora.java +++ b/src/Core/MyFoodora.java @@ -20,7 +20,7 @@ import User.User; import DeliveryStrategy.ContextDeliveryStrategy; /** - * Heart of the project, concatenate all the fonctionalities this project + * Heart of the project, concatenate all the functionalities this project * must have. * */ @@ -52,11 +52,12 @@ public class MyFoodora { public MyFoodora() throws ExceptionUnknownStartegyType{ this.contextTargetProfitStrategy = new ContextTargetProfitStrategy("DeliveryCost"); - this.contextDeliveryPolicy = new ContextDeliveryStrategy("DeliveryCost"); + this.contextDeliveryPolicy = new ContextDeliveryStrategy("FairOccupation"); this.listRestaurant = new ListUser<Restaurant>(); this.listCustomer = new ListUser<Customer>(); this.listManager = new ListUser<Manager>(); this.listCourier = new ListUser<Courier>(); + this.globalListUser = new ListUser<User>(); this.globalHistoric = new HistoricOrder(); } @@ -77,77 +78,103 @@ public class MyFoodora { return null; } + + public User getUserByName(String username, String name){ + for(User user : this.getGlobalListUser().getList()){ + if(username.equals(user.getUsername()) && name.equals(user.getName())){ + return user; + } + } + return null; + } + + public void addUser(User u){ - globalListUser.addUser(u); + this.globalListUser.addUser(u); } public void addCustomer(Customer c){ - listCustomer.addUser(c); + this.listCustomer.addUser(c); } public void addRestaurant(Restaurant r){ - listRestaurant.addUser(r); + this.listRestaurant.addUser(r); } public void addCourier(Courier c){ - listCourier.addUser(c); + this.listCourier.addUser(c); } public void addManager(Manager m){ - listManager.addUser(m); + this.listManager.addUser(m); } public void removeWithID(int typeOfUser,long id){ + User userToRemove = null; for (User user : this.globalListUser.getList()){ if(user.getId() == id){ - this.globalListUser.removeUser(user); + userToRemove = user; } } + if(userToRemove != null){ + this.globalListUser.removeUser(userToRemove); + } if (typeOfUser == CUSTOMER){ + Customer customerToRemove = null; for (Customer customer : this.listCustomer.getList()){ if(customer.getId() == id){ - this.listCustomer.removeUser(customer); + customerToRemove = customer; } } + if(customerToRemove != null){ + this.listCustomer.removeUser(customerToRemove); + } } else if (typeOfUser == RESTAURANT){ + Restaurant restaurantToRemove = null; for (Restaurant restaurant : this.listRestaurant.getList()){ if(restaurant.getId() == id){ - this.listRestaurant.removeUser(restaurant); + restaurantToRemove = restaurant; } } + if(restaurantToRemove != null){ + this.listRestaurant.removeUser(restaurantToRemove); + + } } else if (typeOfUser == MANAGER){ + Manager managerToRemove = null; for (Manager manager : this.listManager.getList()){ if(manager.getId() == id){ - this.listManager.removeUser(manager); + managerToRemove = manager; } } + if(managerToRemove != null){ + this.listManager.removeUser(managerToRemove); + + } } else if (typeOfUser == COURIER){ + Courier courierToRemove = null; for (Courier courier : this.listCourier.getList()){ if(courier.getId() == id){ - this.listCourier.removeUser(courier); + courierToRemove = courier; } } + if(courierToRemove != null){ + this.listCourier.removeUser(courierToRemove); + } } } /** CUSTOM GETTER AND SETTER **/ - public double getTotalIncome(){ - return 1.0; - // fait dans manager - } - private double getTotalProfit(){ - return 1.0; - // fait dans manager - } - private double getProfitForOneOrder(double priceOrder){ + + public double getProfitForOneOrder(double priceOrder){ return priceOrder*markupPercentage + serviceFee - deliveryCost; - // inutile ? + // inutile ? non } /** GENERIC GETTER AND SETTER **/ @@ -230,18 +257,7 @@ public class MyFoodora { public void setDeliveryCost(double deliveryCost) { this.deliveryCost = deliveryCost; } - - /** END GENERIC GETTER AND SETTER - * @throws ExceptionUnknownMealType - * @throws ExceptionUnknownDishType - * @throws ExceptionUnknownStartegyType **/ - - public static void main(String[] args) throws ExceptionUnknownMealType, ExceptionUnknownDishType, ExceptionUnknownStartegyType { - // TODO Auto-generated method stub - MyFoodora myFoodora = new MyFoodora(); - ActiveUserContext activeUser = new ActiveUserContext(myFoodora); - activeUser.setActiveUser(User.login(myFoodora)); - } + public double getLastMonthIncome() { // TODO Auto-generated method stub return 0; diff --git a/src/DeliveryStrategy/ContextDeliveryStrategy.java b/src/DeliveryStrategy/ContextDeliveryStrategy.java index 36add13bcdf919b830bb28b24b4f98bc20c36df4..391d98b20bd2f5d52b05f753ab5cbb2f5194ce65 100644 --- a/src/DeliveryStrategy/ContextDeliveryStrategy.java +++ b/src/DeliveryStrategy/ContextDeliveryStrategy.java @@ -10,31 +10,40 @@ import StrategyProfit.TargetProfitServiceFee; public class ContextDeliveryStrategy implements ContextStrategy { - private StrategyTargetProfitPolicy strategy; + private StrategyDeliveryPolicy strategy; public ContextDeliveryStrategy(String strategyName) throws ExceptionUnknownStartegyType { setStrategy(strategyName); } + @Override public void setStrategy(String strategyName) throws ExceptionUnknownStartegyType{ strategyName = strategyName.toLowerCase().trim(); switch(strategyName){ - case "deliverycost": - strategy = new TargetProfitDeliveryCost(); + case "fairoccupation": + strategy = new FairOccupationDelivery(); break; - case "servicefee": - strategy = new TargetProfitServiceFee(); - break; - case "markup": - strategy = new TargetProfitMarkup(); + case "fastestdelivery": + strategy = new FastestDelivery(); break; default: - throw new ExceptionUnknownStartegyType("Unknown startegy '"+strategyName+"', DeliveryCost, ServiceFee and Markup available."); + throw new ExceptionUnknownStartegyType("Unknown startegy '"+strategyName+"', FairOccupation, FastestDelivery available."); } } - public void execute(MyFoodora myFoodora, double targetProfit){ - strategy.chooseTargetProfit(myFoodora, targetProfit); + @Override + public String toString() { + return strategy.getNameOfStrategy().toString(); + } + + public StrategyDeliveryPolicy getStrategy() { + return strategy; } + public void setStrategy(StrategyDeliveryPolicy strategy) { + this.strategy = strategy; + } + + + } diff --git a/src/DeliveryStrategy/FairOccupationDelivery.java b/src/DeliveryStrategy/FairOccupationDelivery.java index 12618e08f7595cebab051b6fa135f0ef82840057..fa2f279f682bfbcf65a628314d8d1f2971bf7bf9 100644 --- a/src/DeliveryStrategy/FairOccupationDelivery.java +++ b/src/DeliveryStrategy/FairOccupationDelivery.java @@ -3,12 +3,33 @@ package DeliveryStrategy; import java.util.ArrayList; import User.Courier; +import User.Customer; + +public class FairOccupationDelivery extends StrategyDeliveryPolicy { + + + + + + public FairOccupationDelivery() { + super(); + this.setNameOfStrategy("FairOccupation"); + + } + -public class FairOccupationDelivery implements StrategyDeliveryPolicy { @Override - public void chooseCourier(ArrayList<Courier> listOfCourier) { - // TODO Auto-generated method stub + public Courier chooseCourier(Customer customer,ArrayList<Courier> listOfCourier) { + long minNumberOfRun = 100000; + Courier courierToChoose = null; + for(Courier c : listOfCourier){ + if((c.getNbOfOrderOfTheDay() <= minNumberOfRun) & (c.isAvailable() == true)){ + minNumberOfRun = c.getNbOfOrderOfTheDay(); + courierToChoose = c; + } + } + return courierToChoose; } diff --git a/src/DeliveryStrategy/FastestDelivery.java b/src/DeliveryStrategy/FastestDelivery.java index b6f576ff63749cb3cc26599bd830256eff1934b6..f1a0ee894ca373ffde4bee781febc2387d2b730b 100644 --- a/src/DeliveryStrategy/FastestDelivery.java +++ b/src/DeliveryStrategy/FastestDelivery.java @@ -2,14 +2,40 @@ package DeliveryStrategy; import java.util.ArrayList; +import Others.Adress; +import Others.Position; import User.Courier; +import User.Customer; + +public class FastestDelivery extends StrategyDeliveryPolicy{ + + protected String nameOfStrategy; + + + + + public FastestDelivery() { + super(); + this.setNameOfStrategy("FastestDelivery"); + } + -public class FastestDelivery implements StrategyDeliveryPolicy{ @Override - public void chooseCourier(ArrayList<Courier> listOfCourier) { - + public Courier chooseCourier(Customer c,ArrayList<Courier> listOfCourier) { + Adress adress = c.getAdress(); + Courier courierToChoose = null; + double distanceMin = 100000000; + for(Courier courier : listOfCourier){ + Position position = courier.getPosition(); + double distance = Math.sqrt( Math.pow((adress.getX() - position.getX()), 2) + Math.pow((adress.getY() - position.getY()), 2)); + if((distance <= distanceMin)&(courier.isAvailable())){ + distanceMin = distance; + courierToChoose = courier; + } + } + return courierToChoose; } diff --git a/src/DeliveryStrategy/StrategyDeliveryPolicy.java b/src/DeliveryStrategy/StrategyDeliveryPolicy.java index 6ff79f3a4101861f1950ca1f58e0496502eca756..0ae3706e3c92140a22fdc84e8e41879a077697f7 100644 --- a/src/DeliveryStrategy/StrategyDeliveryPolicy.java +++ b/src/DeliveryStrategy/StrategyDeliveryPolicy.java @@ -3,10 +3,31 @@ package DeliveryStrategy; import java.util.ArrayList; import User.Courier; +import User.Customer; -public interface StrategyDeliveryPolicy { +public abstract class StrategyDeliveryPolicy { - public abstract void chooseCourier(ArrayList<Courier> listOfCourier); + protected String nameOfStrategy; + + + + public String getNameOfStrategy() { + return nameOfStrategy; + } + + public void setNameOfStrategy(String nameOfStrategy) { + this.nameOfStrategy = nameOfStrategy; + } + + + @Override + public String toString() { + return nameOfStrategy ; + } + + + + public abstract Courier chooseCourier(Customer c,ArrayList<Courier> listOfCourier); } diff --git a/src/Item/Dish.java b/src/Item/Dish.java index 5fa2635b3c591f8c1d2b58fde07162d20c067610..bca97018cd4605ed761f6bc5e146b1fb7f671c3d 100644 --- a/src/Item/Dish.java +++ b/src/Item/Dish.java @@ -1,22 +1,36 @@ package Item; -public class Dish extends Item implements VisitablePrice{ +public class Dish extends Item{ private String typeInMeal; private double price; + private long nbOfSell; /** CONSTURCTOR **/ public Dish(String name, String typeOfFood, double _price) { super(name, typeOfFood); price = _price; + this.nbOfSell = 0; } /** GETTER AND SETTER **/ + + + + public String getTypeInMeal() { return typeInMeal; } + public long getNbOfSell() { + return nbOfSell; + } + + public void setNbOfSell(long nbOfSell) { + this.nbOfSell = nbOfSell; + } + protected void setTypeInMeal(String _typeInMeal) { this.typeInMeal = _typeInMeal; } @@ -27,19 +41,6 @@ public class Dish extends Item implements VisitablePrice{ this.price = _price; } - /** VISIT LOGIC **/ - - public void acceptPrice(VisitorPrice v) { - if(v instanceof Meal){ - Meal vMeal = (Meal) v; - vMeal.setPrice(vMeal.getPrice()+price); - } - if(v instanceof Dish){ - Dish vDish = (Dish) v; - vDish.setPrice(vDish.getPrice()+price); - } - } - /** OVERRIDE **/ @Override public boolean equals(Object d){ diff --git a/src/Item/FactoryMeal.java b/src/Item/FactoryMeal.java index b06f5255ca1cdbc1a6023920fd951633352e21f7..580ff59ead04c2e1351f1f8f9f46e927640c4b0f 100644 --- a/src/Item/FactoryMeal.java +++ b/src/Item/FactoryMeal.java @@ -4,13 +4,13 @@ import Exception.ExceptionUnknownMealType; public class FactoryMeal { - public Meal createMeal(String typeOfMeal) throws ExceptionUnknownMealType{ + public Meal createMeal(String nameOfMeal, String typeOfMeal) throws ExceptionUnknownMealType{ typeOfMeal=typeOfMeal.toLowerCase().trim(); switch(typeOfMeal){ case "halfmeal": - return new HalfMeal("typeOfMeal","standard"); + return new HalfMeal(nameOfMeal,typeOfMeal); case "fullmeal": - return new FullMeal("typeOfMeal","standard"); + return new FullMeal(nameOfMeal,typeOfMeal); default: throw new ExceptionUnknownMealType("Error, '"+typeOfMeal+"' is unkwon, try HalfMeal or FullMeal."); } diff --git a/src/Item/FullMeal.java b/src/Item/FullMeal.java index 04ec7983158c1b38cb0112ed0223c2971f32d05d..49d18b75ac18a5b1cead52218f1b843d6ae15529 100644 --- a/src/Item/FullMeal.java +++ b/src/Item/FullMeal.java @@ -1,11 +1,16 @@ package Item; +import java.util.ArrayList; +import java.util.Arrays; + public class FullMeal extends Meal { public FullMeal(String name, String typeOfFood) { super(name, typeOfFood); - String [][] pattern = {{"Starter","Dessert"},{"MainDish"}}; + String [][] pattern = {{"Starter"},{"MainDish"},{"Dessert"}}; this.setPatternTypeInMeal(pattern); + this.typeOfMeal = "Full"; + this.listDish = new ArrayList<Dish>(Arrays.asList(null, null, null)); } } diff --git a/src/Item/HalfMeal.java b/src/Item/HalfMeal.java index d68d5c44b83f93fb72da75ba2121207b26b0324d..ded6d14d4b946eb6cc946a2c6fa5f89cea322c64 100644 --- a/src/Item/HalfMeal.java +++ b/src/Item/HalfMeal.java @@ -1,11 +1,18 @@ package Item; +import java.util.ArrayList; +import java.util.Arrays; + public class HalfMeal extends Meal { + protected String typeOfMeal; + public HalfMeal(String name, String typeOfFood) { super(name, typeOfFood); String [][] pattern = {{"Starter","Dessert"},{"MainDish"}}; this.setPatternTypeInMeal(pattern); + this.typeOfMeal = "Half"; + this.listDish = new ArrayList<Dish>(Arrays.asList(null, null)); } } diff --git a/src/Item/Item.java b/src/Item/Item.java index 24cdd6d93b8770c974cecef7986c3317690cd1cf..0ec0bb65c57dd62a6eb2a9beddf9551333dd985e 100644 --- a/src/Item/Item.java +++ b/src/Item/Item.java @@ -2,7 +2,7 @@ package Item; import Order.HistoricOrder; -public abstract class Item implements VisitablePrice { +public abstract class Item { String typeOfFood; String name; diff --git a/src/Item/Meal.java b/src/Item/Meal.java index 9198b01898cf8aee97275b924742707cff08fb85..2302321e1878b1da03bc8d6e55466ef77cd1e3f7 100644 --- a/src/Item/Meal.java +++ b/src/Item/Meal.java @@ -19,11 +19,12 @@ import Order.Order; * chlidrenMealPattern={{"MainDish"},{"Dessert"},{"Drink"}} * */ -public abstract class Meal extends Item implements VisitorPrice{ +public abstract class Meal extends Item{ ArrayList<Dish> listDish = new ArrayList<Dish>(); String [][] patternTypeInMeal; - private String typeOfMeal; + protected String typeOfMeal; + protected long nbOfSell; private double price=0; @@ -31,33 +32,32 @@ public abstract class Meal extends Item implements VisitorPrice{ public Meal(String name,String typeOfFood) { super(name,typeOfFood); + this.nbOfSell = 0; + } /** add and remove dishes **/ public void addDish(Dish dish){ - if(dish.getTypeOfFood() != this.getTypeOfFood()){ - System.out.println("Trying to add "+dish.getTypeOfFood()+" in "+this.getTypeOfFood()+" menu, resulted in error."); - }else{ - int idInMenu=-1; - int idInMenuInc=0; - for(String[] tabOfType : this.getPatternTypeInMeal()){ - for(String typeFromPatternType : tabOfType){ - if(typeFromPatternType==dish.getTypeInMeal()){ - idInMenu=idInMenuInc; - } + int idInMenu=-1; + int idInMenuInc=0; + for(String[] tabOfType : this.getPatternTypeInMeal()){ + for(String typeFromPatternType : tabOfType){ + if(typeFromPatternType==dish.getTypeInMeal()){ + idInMenu=idInMenuInc; } - 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); - } + idInMenuInc+=1; + } + System.out.println(dish.getTypeInMeal()); + 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); } } } @@ -88,18 +88,30 @@ public abstract class Meal extends Item implements VisitorPrice{ /** GETTER AND SETTER **/ + + public String getTypeOfMeal() { return typeOfMeal; } + public long getNbOfSell() { + return nbOfSell; + } + + public void setNbOfSell(long nbOfSell) { + this.nbOfSell = nbOfSell; + } + protected void setTypeOfMeal(String _typeOfMeal) { this.typeOfMeal = _typeOfMeal; } public double getPrice(){ + price = 0; + for(Dish dish : listDish){ + if(dish!=null) + price+=dish.getPrice(); + } return price; } - public void setPrice(double _price){ - price = _price; - } public ArrayList<Dish> getListDish() { return listDish; } @@ -110,24 +122,6 @@ public abstract class Meal extends Item implements VisitorPrice{ this.patternTypeInMeal = patternTypeInMeal; } - /** VISIT LOGIC **/ - - @Override - public void acceptPrice(VisitorPrice v){ - price=0; // reseting price - if(v instanceof Order){ - Order vOrder = (Order) v; - for(Dish item: listDish){ - item.acceptPrice(this); - } - vOrder.setPrice(vOrder.getPrice()+this.getPrice()*0.95); - } - } - - @Override - public void visitPrice(VisitablePrice v) { - v.acceptPrice(this); - } /** OVERRIDE **/ @Override diff --git a/src/Offers/BirthdayOffer.java b/src/Offers/BirthdayOffer.java new file mode 100644 index 0000000000000000000000000000000000000000..09d00a419a09656c687979d6eb2acedb6ac7e2f5 --- /dev/null +++ b/src/Offers/BirthdayOffer.java @@ -0,0 +1,59 @@ +package Offers; + +import java.util.ArrayList; + +import Item.Meal; + +public class BirthdayOffer implements ObservableOffer { + + + + private boolean state; + private ArrayList<Observer> observers = new ArrayList<Observer>(); + + + + public BirthdayOffer(boolean state, ArrayList<Observer> observers) { + super(); + this.state = true; + this.observers = new ArrayList<Observer>(); + } + + @Override + public void attachObserver(Observer o) { + // TODO Auto-generated method stub + + } + + @Override + public void detachObserver(Observer o) { + // TODO Auto-generated method stub + + } + + @Override + public void notifyall() { + // TODO Auto-generated method stub + + } + + public boolean isState() { + return state; + } + + public void setState(boolean state) { + this.state = state; + } + + public ArrayList<Observer> getObservers() { + return observers; + } + + public void setObservers(ArrayList<Observer> observers) { + this.observers = observers; + } + + + + +} diff --git a/src/Offers/MealOfTheWeek.java b/src/Offers/MealOfTheWeek.java index 38afc3e35fdf0b48619fa88ff5d7281a05872816..68b750ad8e7c6a1a3de717e88ffddc3532c71be3 100644 --- a/src/Offers/MealOfTheWeek.java +++ b/src/Offers/MealOfTheWeek.java @@ -16,9 +16,9 @@ public class MealOfTheWeek implements ObservableOffer { public MealOfTheWeek(boolean state, Meal meal,ArrayList<Observer> observers) { super(); - this.state = state; + this.state = true; this.meal = meal; - this.observers = observers; + this.observers = new ArrayList<Observer>(); } diff --git a/src/Order/Order.java b/src/Order/Order.java index 417637ab09d89a29fd7cc50ee3b2968cc0f087e5..c4e6cf46b88cd8a810efd8c2e72ef70007a1d0b2 100644 --- a/src/Order/Order.java +++ b/src/Order/Order.java @@ -8,24 +8,47 @@ import Item.Meal; import Item.VisitablePrice; import Item.VisitorPrice; import Others.Period; +import User.Restaurant; -public class Order implements VisitorPrice, Comparable<Order>{ +public class Order implements Comparable<Order>{ private double price; private Others.Date date; private boolean finalized; + private String nameOrder; + private Restaurant restaurantAttached; + + public String getNameOrder() { + return nameOrder; + } ArrayList<Dish> listDish; ArrayList<Meal> listMeal; public Order() { - // TODO Auto-generated constructor stub + super(); + + this.listDish = new ArrayList<Dish>(); + this.listMeal = new ArrayList<Meal>(); } + public Order(String _name, Restaurant _restaurant) { + super(); + + this.listDish = new ArrayList<Dish>(); + this.listMeal = new ArrayList<Meal>(); + nameOrder = _name; + restaurantAttached = _restaurant; + } + /** CUSTOM **/ + @SuppressWarnings("deprecation") public void finalize(){ - Date date = new Date(); + int theDay = new java.util.Date().getDay(); + int theMonth = new java.util.Date().getMonth() + 1 ; + int theYear = new java.util.Date().getYear() + 1900; + this.date = new Others.Date(theYear, theMonth, theDay); finalized = true; } @@ -101,15 +124,19 @@ public class Order implements VisitorPrice, Comparable<Order>{ public void add(Dish d){ listDish.add(d); + //price = price + d.getPrice(); } public void add(Meal m){ listMeal.add(m); + //price = price + m.getPrice(); } public void remove(Dish d){ listDish.remove(d); + //price = price - d.getPrice(); } public void remove(Meal m){ listMeal.remove(m); + //price = price - m.getPrice(); } public void removeDishById(int d){ listDish.remove(d); @@ -124,6 +151,13 @@ public class Order implements VisitorPrice, Comparable<Order>{ return finalized; } public double getPrice(){ + price = 0; + for(Meal meal : listMeal){ + price += meal.getPrice()*(1-restaurantAttached.getGeneralDiscountFactor()); + } + for(Dish dish : listDish){ + price += dish.getPrice(); + } return price; } public void setPrice(double price) { @@ -132,14 +166,22 @@ public class Order implements VisitorPrice, Comparable<Order>{ public Others.Date getDate(){ return date; } - @Override - public void visitPrice(VisitablePrice v) { - for(Dish dish:listDish){ - dish.acceptPrice(this); - } - for(Meal meal:listMeal){ - meal.acceptPrice(this); - } + + + public ArrayList<Dish> getListDish() { + return listDish; + } + + public void setListDish(ArrayList<Dish> listDish) { + this.listDish = listDish; + } + + public ArrayList<Meal> getListMeal() { + return listMeal; + } + + public void setListMeal(ArrayList<Meal> listMeal) { + this.listMeal = listMeal; } @Override diff --git a/src/Others/Adress.java b/src/Others/Adress.java index e91df734d70a57992308dbd13d29a5fc44c28bd8..a6667c912e5fc3411d1147e03cb15db7262b2fd2 100644 --- a/src/Others/Adress.java +++ b/src/Others/Adress.java @@ -39,6 +39,12 @@ public class Adress { } - + public static Adress fromStr(String str){ + String [] arrStr = str.split(","); + if(arrStr.length==2) + if(arrStr[0].matches("-?\\d+(\\.\\d+)?") && arrStr[1].matches("-?\\d+(\\.\\d+)?")) + return new Adress(Double.parseDouble(arrStr[0]),Double.parseDouble(arrStr[1])); + return new Adress(0,0); + } } diff --git a/src/StrategyProfit/ContextTargetProfitStrategy.java b/src/StrategyProfit/ContextTargetProfitStrategy.java index 944a3348c0b35436ca4cc6b8b597bc526757fa49..313b9081804b2892dd00e33c6cb50b1fb56eeb55 100644 --- a/src/StrategyProfit/ContextTargetProfitStrategy.java +++ b/src/StrategyProfit/ContextTargetProfitStrategy.java @@ -1,9 +1,10 @@ package StrategyProfit; +import Core.ContextStrategy; import Core.MyFoodora; import Exception.ExceptionUnknownStartegyType; -public class ContextTargetProfitStrategy { +public class ContextTargetProfitStrategy implements ContextStrategy { public StrategyTargetProfitPolicy strategy; @@ -32,4 +33,21 @@ public class ContextTargetProfitStrategy { strategy.chooseTargetProfit(myFoodora, targetProfit); } + @Override + public String toString() { + return strategy.toString(); + } + + public StrategyTargetProfitPolicy getStrategy() { + return strategy; + } + + public void setStrategy(StrategyTargetProfitPolicy strategy) { + this.strategy = strategy; + } + + + + + } diff --git a/src/StrategyProfit/StrategyTargetProfitPolicy.java b/src/StrategyProfit/StrategyTargetProfitPolicy.java index c1e5f7d44ba75c3231a9b4ac657439cdc382b0bc..0bb6ec055b98e465425b39add1ee32ae84fa95c8 100644 --- a/src/StrategyProfit/StrategyTargetProfitPolicy.java +++ b/src/StrategyProfit/StrategyTargetProfitPolicy.java @@ -3,7 +3,7 @@ package StrategyProfit; import Core.MyFoodora; public abstract class StrategyTargetProfitPolicy { - private String nameOfStrategy="undefined"; + protected String nameOfStrategy; public abstract void chooseTargetProfit(MyFoodora myFoodora, double targetProfit); public String getNameOfStrategy() { @@ -12,4 +12,11 @@ public abstract class StrategyTargetProfitPolicy { protected void setNameOfStrategy(String nameOfStrategy) { this.nameOfStrategy = nameOfStrategy; } + + @Override + public String toString() { + return nameOfStrategy; + } + + } diff --git a/src/User/Courier.java b/src/User/Courier.java index bf8a8a0e7e1d080bfcc21c228ed688312194a8a8..97ca2a4944bdca5fa17416082e7dae456f256305 100644 --- a/src/User/Courier.java +++ b/src/User/Courier.java @@ -1,8 +1,12 @@ package User; import java.util.ArrayList; +import java.util.Date; +import java.util.Scanner; +import Cli.Input; import Core.MyFoodora; +import Order.HistoricOrder; import Order.Order; import Others.Adress; import Others.Position; @@ -24,7 +28,6 @@ public class Courier extends HumanUser { private Position position; private long nbOfLivraison; private boolean available; - private int typeOfUser; /** CONSTRUCTOR **/ @@ -34,9 +37,13 @@ public class Courier extends HumanUser { super(phoneNumber, name, username, mail, password, adress, activated, birthdayDate, surname); this.position = new Position(0,0); this.nbOfLivraison = 0; - this.available = false; + this.available = true; this.typeOfUser = COURIER; } + + public Courier(){ + + } public Position getPosition() { @@ -48,6 +55,15 @@ public class Courier extends HumanUser { this.position = position; } + + + public boolean isAvailable() { + return available; + } + + public void setAvailable(boolean available) { + this.available = available; + } public long getNbOfLivraison() { return nbOfLivraison; @@ -80,10 +96,10 @@ public class Courier extends HumanUser { public void unregister(MyFoodora foodora){ ListUser<Courier> listOfCourier = foodora.getListCourier(); - boolean isNotIn = false; + boolean isNotIn = true; for (Courier c : listOfCourier.getList()) { if(c == this){ - isNotIn = true; + isNotIn = false; } } if(isNotIn == true){ @@ -102,12 +118,33 @@ public class Courier extends HumanUser { } else{ o.finalize(); + historic.addOrder(o); + this.nbOfLivraison++; + this.setNotAvailable(); } } + + public long getNbOfOrderOfTheDay (){ + @SuppressWarnings("deprecation") + int theDay = new java.util.Date().getDay(); + int theMonth = new java.util.Date().getMonth() +1 ; + int theYear = new java.util.Date().getYear() + 1900; + Others.Date date = new Others.Date(theYear,theMonth,theDay); + long nbOfOrderOfTheDay = 0; + for(Order order : this.historic.getListOrder()){ + if((order.getDate().getIntDay() == date.getIntDay())&(order.getDate().getIntMonth() == date.getIntMonth())&(order.getDate().getIntYear() == date.getIntYear())){ + nbOfOrderOfTheDay++; + } + } + return nbOfOrderOfTheDay; + } + + + public void refuseDelivery(Order o){ - System.out.println("The courier" + this.id + "has refused the delivery"); + System.out.println("The courier " + this.name + " has refused the delivery"); } diff --git a/src/User/Customer.java b/src/User/Customer.java index fefe4269c1c1a153cccd8116440c8e484ea14369..c0ed572abe18933fd86c38eb4acfa9018e9c1eb5 100644 --- a/src/User/Customer.java +++ b/src/User/Customer.java @@ -1,5 +1,6 @@ package User; +import java.util.ArrayList; import java.util.Scanner; import Cli.Confirm; @@ -14,41 +15,111 @@ import Others.IDCard; import Order.HistoricOrder; import Order.Order; import Cli.Input; +import Core.MyFoodora; +import Item.Dish; import Item.FactoryDish; +import Item.Item; import Item.Meal; import Item.MealFactory; import Offers.Observer; public class Customer extends HumanUser implements VisiterCard,Observer { + + public static final int UNKNOWN = 0; + public static final int COURIER = 1; + public static final int RESTAURANT = 2; + public static final int CUSTOMER = 3; + public static final int MANAGER = 4; private boolean spamAgree; - private HistoricOrder historique; private FidelityCard card; private IDCard idCard; - private int typeOfUser; + private ArrayList<Order> listOrder = new ArrayList<Order>(); public Customer(long phoneNumber, String name, String username, String mail, String password, - Adress adress, boolean activated, String birthdayDate, String surname, boolean spamAgree) { + Adress adress, boolean activated, String birthdayDate, String surname) { super(phoneNumber, name, username, mail, password, adress, activated, birthdayDate, surname); - this.spamAgree = spamAgree; - this.historique = new HistoricOrder(); + this.spamAgree = true; this.card = new BasicFidelityCard(); this.typeOfUser = CUSTOMER; } - public FidelityCard getCard() { return card; } + public boolean isSpamAgree() { + return spamAgree; + } + + public void setSpamAgree(boolean spamAgree) { + this.spamAgree = spamAgree; + } + @Override public String toString() { - return "Customer [spamAgree=" + spamAgree + ", historique=" + historique + ", card=" + card + "]"; + return "Customer [spamAgree=" + spamAgree + ", historique=" + historic + ", card=" + card + "]"; } + + public void placeOrder(Restaurant restaurant, String mealOrDish, ArrayList<String> listOfItem, MyFoodora foodora){ + ArrayList<Dish> cartOfRestaurant = restaurant.getListOfDish(); + ArrayList<Meal> cartOfMeal = restaurant.getListOfMeal(); + Order order = new Order(); + if(mealOrDish == "Dish"){ + for(String item : listOfItem){ + boolean isIn = false; + Dish dishToChoose = null; + for(Dish dish : cartOfRestaurant){ + if(dish.getName() == item){ + isIn = true; + dishToChoose = dish; + dish.setNbOfSell(dish.getNbOfSell() + 1); + } + if(isIn = false){ + System.out.println("This dish is not in the cart"); + } + else{ + order.add(dishToChoose); + } + } + } + } + else if(mealOrDish == "Meal"){ + for(String item : listOfItem){ + boolean isIn = false; + Meal mealToChoose = null; + for(Meal meal : cartOfMeal){ + if(meal.getName() == item){ + isIn = true; + mealToChoose = meal; + meal.setNbOfSell(meal.getNbOfSell() + 1); + } + } + if(isIn = false){ + System.out.println("This meal is not in the menu"); + } + else{ + order.add(mealToChoose); + } + } + } + this.historic.addOrder(order); + restaurant.historic.addOrder(order); + Courier chosenCourier = foodora.getContextDeliveryPolicy().getStrategy().chooseCourier(this,foodora.getListCourier().getList()); + chosenCourier.acceptDelivery(order); + foodora.getGlobalHistoric().addOrder(order); + if (this.card instanceof PointFidelityCard){ + ((PointFidelityCard) this.card).setNbOfPoint(this.getPointInTheCard() + 1); + } + } + + + /* + public void placeOrder(Restaurant restaurant){ Order order = new Order(); System.out.println(restaurant.toString()); @@ -72,7 +143,7 @@ public class Customer extends HumanUser implements VisiterCard,Observer { 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) + Meal newmeal = factory1.createMeal("fullmeal", "meal1", "meal1"); } if (choice == "HalfMeal"){ System.out.println("listedesDish"); //� faire @@ -116,7 +187,7 @@ public class Customer extends HumanUser implements VisiterCard,Observer { } - } + } */ public void registerFidelityPlan(String newTypeOfFidelityCard){ if(newTypeOfFidelityCard == this.card.returnType()){ @@ -141,7 +212,7 @@ public class Customer extends HumanUser implements VisiterCard,Observer { } } - public void unregisterFidelityPlan(String newTypeOfFidelityCard){ + public void unregisterFidelityPlan(){ if(this.card.returnType() == "Basic"){ System.out.println("You already have this card");} @@ -152,7 +223,7 @@ public class Customer extends HumanUser implements VisiterCard,Observer { } public HistoricOrder getHistorique() { - return historique; + return historic; } public long getPointInTheCard(){ @@ -176,6 +247,7 @@ public class Customer extends HumanUser implements VisiterCard,Observer { } else { this.spamAgree = true; + } } @@ -191,18 +263,26 @@ public class Customer extends HumanUser implements VisiterCard,Observer { @Override public void update() { - + System.out.println(); } + + + public void createOrder(String name, Restaurant restaurant){ + Order order = new Order(name,restaurant); + listOrder.add(order); + } - - - - - - + public Order getOrderByName(String string) { + for(Order order : listOrder){ + if(order.getNameOrder() == string) + return order; + } + return null; } +} + diff --git a/src/User/HumanUser.java b/src/User/HumanUser.java index e0a2d09d59355cbe56d6beccca2af6b26fb88a29..3a887dc0eca91bac61b8777016899bc81d5e3530 100644 --- a/src/User/HumanUser.java +++ b/src/User/HumanUser.java @@ -12,5 +12,9 @@ public class HumanUser extends User { this.birthdayDate = birthdayDate; this.surname = surname; } + + public HumanUser(){ + + } } diff --git a/src/User/ListUser.java b/src/User/ListUser.java index 8b2432de44ead06ee422107cdc32e0d6359437e0..e5c52d4cf29ec13ff239b79cecbb0178e7bef852 100644 --- a/src/User/ListUser.java +++ b/src/User/ListUser.java @@ -1,11 +1,9 @@ package User; import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; -import java.util.List; -public class ListUser<T extends User> implements Iterable{ +public class ListUser<T extends User> implements Iterable<Object>{ private ArrayList<T> listUser = new ArrayList<T>(); /** CUSTOM **/ @@ -36,7 +34,15 @@ public class ListUser<T extends User> implements Iterable{ return listUser; } @Override - public Iterator iterator() { + public String toString(){ + String str = ""; + for(User u : listUser){ + str += u.toString() + "\n"; + } + return str; + } + @Override + public Iterator<Object> iterator() { // TODO Auto-generated method stub return null; } diff --git a/src/User/Manager.java b/src/User/Manager.java index 751b2f8615d6474b640f2e35136504f944bcba0c..2fbc15d6171577537c1c5216d739ae291b2a1ef6 100644 --- a/src/User/Manager.java +++ b/src/User/Manager.java @@ -1,6 +1,8 @@ package User; import Core.MyFoodora; import DeliveryStrategy.ContextDeliveryStrategy; +import Item.Dish; +import Item.HalfMeal; import Order.HistoricOrder; import Order.Order; @@ -26,7 +28,6 @@ public class Manager extends HumanUser { public static final int CUSTOMER = 3; public static final int MANAGER = 4; - private int typeOfUser; public Manager(long phoneNumber, String name, String username, String mail, String password, Adress adress, boolean activated, String birthdayDate, String surname) { @@ -34,6 +35,8 @@ public class Manager extends HumanUser { this.typeOfUser = MANAGER; } + + public void addUser(long phoneNumber, String name, String username, String mail, String password, Adress adress, boolean activated , String birthdayDate, String surname,MyFoodora foodora, int typeOfUser, String kindOfUser){ @@ -55,7 +58,7 @@ public class Manager extends HumanUser { } } else if (kindOfUser == "Moral"){ - MoralUser moralUser = factory.createMoralUser(phoneNumber, surname, username, mail, password, adress, activated, typeOfUser); + MoralUser moralUser = factory.createMoralUser(phoneNumber, name, username, mail, password, adress, activated, typeOfUser); if(moralUser != null){ foodora.addUser(moralUser); if(typeOfUser == RESTAURANT){ @@ -102,7 +105,13 @@ public class Manager extends HumanUser { } public double getTotalProfit(Others.Period period, MyFoodora foodora){ - return getTotalIncome(period,foodora)*(foodora.getMarkupPercentage()+foodora.getServiceFee() - foodora.getDeliveryCost()); + HistoricOrder historicOfFoodora = foodora.getGlobalHistoric(); + ArrayList<Order> listOrderOverPeriod = Order.getListOfOrderInAPeriod(historicOfFoodora,period); + double totalIncome = 0; + for(Order order : listOrderOverPeriod){ + totalIncome = totalIncome + order.getPrice()*foodora.getMarkupPercentage() + foodora.getServiceFee() - foodora.getDeliveryCost(); + } + return totalIncome; } public double getAverageIncomePerCustomer(MyFoodora foodora, Others.Period period){ @@ -117,8 +126,13 @@ public class Manager extends HumanUser { } double totalIncome = getTotalIncome(period, foodora); - - return totalIncome/nbOfCustomer; + if(nbOfCustomer != 0){ + return totalIncome/nbOfCustomer; + + } + else { + return 0; + } } @@ -159,7 +173,7 @@ public class Manager extends HumanUser { mostSellingRestaurant = restaurant; } } - return mostSellingRestaurant.nameOf(); + return mostSellingRestaurant.getName(); } public String getLeastSellingRestaurant(MyFoodora foodora){ @@ -187,11 +201,10 @@ public class Manager extends HumanUser { for (Courier courier : listOfCourier.getList()) { if(courier.getNbOfLivraison() <= leastNbOfSell){ leastSeller = courier; + leastNbOfSell = leastSeller.getNbOfLivraison(); } } - System.out.println(leastSeller.toString()); - System.out.println(leastSeller.getNbOfLivraison()); - return leastSeller.toString() ; + return leastSeller.getName() ; } @@ -202,11 +215,10 @@ public class Manager extends HumanUser { for (Courier courier : listOfCourier.getList()) { if(courier.getNbOfLivraison() >= mostNbOfSell){ mostSeller = courier; + mostNbOfSell = mostSeller.getNbOfLivraison(); } } - System.out.println(mostSeller.toString()); - System.out.println(mostSeller.getNbOfLivraison()); - return mostSeller.toString() ; + return mostSeller.getName() ; } @@ -299,8 +311,14 @@ public class Manager extends HumanUser { } + public ArrayList<HalfMeal> getSortedListOfHalfMeal (Restaurant restaurant){ + return restaurant.getSortListOfHalfMeal(); + } + public ArrayList<Dish> getSortedListOfDish (Restaurant restaurant){ + return restaurant.getSortListOfDish(); + } } diff --git a/src/User/MoralUser.java b/src/User/MoralUser.java index 4cade1f7b658a257dd8fb71a184e9dd97fe2512e..93600add16d0ec6570dec4c7a6519dff1622031c 100644 --- a/src/User/MoralUser.java +++ b/src/User/MoralUser.java @@ -9,5 +9,9 @@ public class MoralUser extends User { super(phoneNumber, name, username, mail, password, adress, activated); // TODO Auto-generated constructor stub } + + public MoralUser(){ + + } } diff --git a/src/User/Restaurant.java b/src/User/Restaurant.java index 56de3aa06bbc2f0b3731aa5c93f4e773c5f4ae05..d3c92458a8d1fc7b2e069658374501123b14fba5 100644 --- a/src/User/Restaurant.java +++ b/src/User/Restaurant.java @@ -1,8 +1,15 @@ package User; +import java.lang.reflect.Array; import java.util.ArrayList; +import Exception.ExceptionUnknownDishType; +import Exception.ExceptionUnknownMealType; import Item.Dish; +import Item.FactoryDish; +import Item.FactoryMeal; +import Item.HalfMeal; +import Item.Item; import Item.Meal; import Others.Adress; @@ -10,9 +17,10 @@ public class Restaurant extends MoralUser { - ArrayList<Meal> listOfMeal; - ArrayList<Dish> listOfDish; - private int typeOfUser; + private ArrayList<Meal> listOfMeal; + private ArrayList<Dish> listOfDish; + private double generalDiscountFactor; + private double specialDiscountFactor; /** CONSTRUCTOR **/ @@ -22,28 +30,75 @@ public class Restaurant extends MoralUser { this.listOfMeal = new ArrayList<Meal>(); this.listOfDish = new ArrayList<Dish>(); this.typeOfUser = RESTAURANT; + this.generalDiscountFactor = 0.05; + this.specialDiscountFactor = 0.1; } - - /** SETTERS**/ - - - - - public void addMeal(Meal m){ + public Restaurant(){ + + } + + + /** SETTERS + * @throws ExceptionUnknownMealType **/ + public void addMeal(String nameOfMeal, String typeOfMeal, ArrayList<Dish> listOfDish) throws ExceptionUnknownMealType{ + FactoryMeal factory1 = new FactoryMeal(); + Meal m = factory1.createMeal(nameOfMeal, typeOfMeal); + if(((listOfDish.size() !=2) &(typeOfMeal == "Half")) || ((listOfDish.size() !=3) &(typeOfMeal == "Full"))){ + System.out.println("Not the correct list of Dish"); + } + if(typeOfMeal == "Half"){ + for(Dish dish : listOfDish){ + m.addDish(dish); + } + } 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 Meal createMeal(String nameOfMeal, String typeOfMeal) throws ExceptionUnknownMealType{ + FactoryMeal factory = new FactoryMeal(); + Meal m = factory.createMeal(nameOfMeal, typeOfMeal); + listOfMeal.add(m); + return m; + } + + public void addDishToMeal(Dish d, Meal m){ + m.addDish(d); + } + + public Dish getDishByName(String name){ + for(Dish d : listOfDish){ + if(d.getName() == name){ + return d; + } + } + return null; + } + + public Meal getMealByName(String name){ + for(Meal m : listOfMeal){ + if(m.getName() == name){ + return m; + } + } + return null; + } + + public Item getItemByName(String name){ + Item item = getMealByName(name); + if(item == null) + item = getDishByName(name); + return item; + } public String nameOf(){ return this.getName(); @@ -51,7 +106,7 @@ public class Restaurant extends MoralUser { @Override public String toString() { - return "Restaurant [listOfMeal=" + listOfMeal + ", listOfDish=" + listOfDish + "]"; + return "Restaurant =" + this.name; } @@ -65,7 +120,25 @@ public class Restaurant extends MoralUser { } - public void addDish(Dish d){ + public double getGeneralDiscountFactor() { + return generalDiscountFactor; + } + + public void setGeneralDiscountFactor(double generalDiscountFactor) { + this.generalDiscountFactor = generalDiscountFactor; + } + + public double getSpecialDiscountFactor() { + return specialDiscountFactor; + } + + public void setSpecialDiscountFactor(double specialDiscountFactor) { + this.specialDiscountFactor = specialDiscountFactor; + } + + public void addDish(String typeInMeal, String name, String typeOfFood, double price) throws ExceptionUnknownDishType{ + FactoryDish factory1 = new FactoryDish(); + Dish d = factory1.createDish(typeInMeal, name, typeOfFood, price); boolean isalready = false; for (Dish dish : this.listOfDish) { if(dish.equals(d)){ @@ -89,4 +162,52 @@ public class Restaurant extends MoralUser { this.listOfDish.remove(d); } + public ArrayList<HalfMeal> getSortListOfHalfMeal(){ + ArrayList<HalfMeal> listOfHalMeal = new ArrayList<HalfMeal>(); + ArrayList<HalfMeal> sortedListOfHalMeal = new ArrayList<HalfMeal>(); + for(Meal m : this.listOfMeal){ + if(m.getTypeOfMeal() == "Half"){ + listOfHalMeal.add((HalfMeal) m); + } + } + while(listOfHalMeal.isEmpty() == false){ + long maxNbOfSell = 0; + HalfMeal maxSelledInTheList = null; + for(HalfMeal m : listOfHalMeal){ + if(m.getNbOfSell() >= maxNbOfSell){ + maxNbOfSell = m.getNbOfSell(); + maxSelledInTheList = m; + } + } + sortedListOfHalMeal.add(maxSelledInTheList); + listOfHalMeal.remove(maxSelledInTheList); + + } + return sortedListOfHalMeal; + } + + + public ArrayList<Dish> getSortListOfDish(){ + ArrayList<Dish> listToSort = new ArrayList<Dish>(); + ArrayList<Dish> sortedListOfDish = new ArrayList<Dish>(); + for(Dish dish : listOfDish){ + listToSort.add(dish); + } + while(listToSort.isEmpty() == false){ + long maxNbOfSell = 0; + Dish maxSelledInTheList = null; + for(Dish d : listToSort){ + if(d.getNbOfSell() >= maxNbOfSell){ + maxNbOfSell = d.getNbOfSell(); + maxSelledInTheList = d; + } + } + sortedListOfDish.add(maxSelledInTheList); + listToSort.remove(maxSelledInTheList); + + } + return sortedListOfDish; + } + + } diff --git a/src/User/User.java b/src/User/User.java index e4d9d3d926c545dcd85bba56f850df8d59a78c55..25be834052b1e872b57d7eda727bd52aa9868ff1 100644 --- a/src/User/User.java +++ b/src/User/User.java @@ -11,13 +11,13 @@ import Order.HistoricOrder; public abstract class User implements Comparable<User> { protected long id; - private long phoneNumber; - private String name,username,mail,password; - private Adress adress; - private boolean activated; - private HistoricOrder historic; - private boolean isLogged; - private int typeOfUser; + protected long phoneNumber; + protected String name,username,mail,password; + protected Adress adress; + protected boolean activated; + protected HistoricOrder historic; + protected boolean isLogged; + protected int typeOfUser; public static final int UNKNOWN = 0; public static final int COURIER = 1; @@ -25,9 +25,11 @@ public abstract class User implements Comparable<User> { public static final int CUSTOMER = 3; public static final int MANAGER = 4; - /** CONSTRUCTOR **/ + public User() { + } + public User(long phoneNumber, String name, String username, String mail, String password, Adress adress, boolean activated) { super(); @@ -35,7 +37,6 @@ public abstract class User implements Comparable<User> { this.id = idUser.getNextSerialNumber(); this.historic = new HistoricOrder(); this.isLogged = false; - this.typeOfUser = 0; this.phoneNumber = phoneNumber; this.name = name; @@ -49,13 +50,8 @@ public abstract class User implements Comparable<User> { /** CUSTOM **/ - public static User login(MyFoodora foodora){ - String usernameTest = Input.string("Please writte your username"); - String passwordTest = Input.string("Please writte your password"); - return foodora.getUserByLogin(usernameTest, passwordTest); - } public boolean isLoginCorrect(String username, String password) { - if(this.username == username && this.password == password) + if(this.username.equals(username) && this.password.equals(password)) return true; return false; } diff --git a/src/UserFactoryPattern/HumanUserFactory.java b/src/UserFactoryPattern/HumanUserFactory.java index 4d2ff1154b209cf402073f7290f2f5267ac2c426..cc994577f402ac650415f7cfca9ab2da342c96ed 100644 --- a/src/UserFactoryPattern/HumanUserFactory.java +++ b/src/UserFactoryPattern/HumanUserFactory.java @@ -22,9 +22,8 @@ public class HumanUserFactory extends UserFactory{ return courier; } else if (typeOfUser == CUSTOMER){ - boolean spamAgree = Confirm.text("Do you agree to receive offers ?"); Customer customer = new Customer(phoneNumber, name, username, mail, password, - adress, activated, birthdayDate, surname, spamAgree); + adress, activated, birthdayDate, surname); return customer ; } else if (typeOfUser == MANAGER){ diff --git a/src/test/TestCourier.java b/src/test/TestCourier.java new file mode 100644 index 0000000000000000000000000000000000000000..c7c0f05d261a2b9973728175e8f54ad712676221 --- /dev/null +++ b/src/test/TestCourier.java @@ -0,0 +1,113 @@ +package test; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; + +import Core.MyFoodora; +import Exception.ExceptionUnknownDishType; +import Exception.ExceptionUnknownStartegyType; +import Others.Adress; +import Others.Period; +import Others.Position; +import User.Courier; +import User.Customer; +import User.Manager; +import User.Restaurant; + +public class TestCourier { + + public static final int UNKNOWN = 0; + public static final int COURIER = 1; + public static final int RESTAURANT = 2; + public static final int CUSTOMER = 3; + public static final int MANAGER = 4; + + @Test + public void testSetPosition() { + Courier courier = new Courier(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou"); + courier.setPosition(new Position(10.0, 15.0)); + assertTrue(courier.getPosition().getX() == 10.0); + } + + @Test + public void testSetAvailable() { + Courier courier = new Courier(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou"); + courier.setAvailable(); + assertTrue(courier.isAvailable()); + } + + @Test + public void testSetNotAvailable() { + Courier courier = new Courier(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou"); + courier.setNotAvailable(); + assertTrue(courier.isAvailable() == false); + } + + @Test + public void testRegister() throws ExceptionUnknownStartegyType { + Courier martin = new Courier(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou"); + MyFoodora foodora = new MyFoodora(); + martin.register(foodora); + boolean isIn = false; + for(Courier courier : foodora.getListCourier().getList()){ + if(courier.getName() == "martin"){ + isIn = true; + } + } + + assertTrue(isIn); + } + + @Test + public void testUnregister() throws ExceptionUnknownStartegyType { + Courier martin = new Courier(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou"); + MyFoodora foodora = new MyFoodora(); + martin.register(foodora); + martin.unregister(foodora); + boolean isIn = false; + for(Courier courier : foodora.getListCourier().getList()){ + if(courier.getName() == "martin"){ + isIn = true; + } + } + + assertTrue(isIn == false); + } + + @Test + public void testAcceptDelivery() throws ExceptionUnknownDishType, ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + Courier martin = (Courier) foodora.getUserByName("martin", "martin"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + assertTrue(martin.getHistoricOrder().getListOrder().size() !=0); + } + + @Test + public void testGetNbOfOrderOfTheDay() throws ExceptionUnknownDishType, ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + Courier martin = (Courier) foodora.getUserByName("martin", "martin"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + assertTrue(martin.getNbOfOrderOfTheDay() == 1); + } +} diff --git a/src/test/TestCustomer.java b/src/test/TestCustomer.java new file mode 100644 index 0000000000000000000000000000000000000000..40e9f0ce6d0a1f7f41d6a40c105855c8797a9f60 --- /dev/null +++ b/src/test/TestCustomer.java @@ -0,0 +1,110 @@ +package test; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; + +import Cards.BasicFidelityCard; +import Cards.FidelityCard; +import Core.MyFoodora; +import Exception.ExceptionUnknownDishType; +import Exception.ExceptionUnknownStartegyType; +import Item.Dish; +import Others.Adress; +import User.Customer; +import User.Manager; +import User.Restaurant; + +public class TestCustomer { + + public static final int UNKNOWN = 0; + public static final int COURIER = 1; + public static final int RESTAURANT = 2; + public static final int CUSTOMER = 3; + public static final int MANAGER = 4; + + @Test + public void testGetCard() throws ExceptionUnknownStartegyType{ + Customer henry = new Customer(0245, "henry", "henry", "henry.dupont@homtail.fr", "123456789", new Adress(10.2, 12.0), true, "25/02/1578", "henrynou"); + FidelityCard card = henry.getCard(); + assertTrue(card.returnType() == "Basic"); + + } + + @Test + public void testPlaceOrder() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + assertTrue(henry.getHistoricOrder().getListOrder().size() == 1); + } + + @Test + public void testRegisterFidelityPlan() { + Customer henry = new Customer(0245, "henry", "henry", "henry.dupont@homtail.fr", "123456789", new Adress(10.2, 12.0), true, "25/02/1578", "henrynou"); + henry.registerFidelityPlan("Point"); + FidelityCard card = henry.getCard(); + assertTrue(card.returnType() == "Point"); + + } + + @Test + public void testUnregisterFidelityPlan() { + Customer henry = new Customer(0245, "henry", "henry", "henry.dupont@homtail.fr", "123456789", new Adress(10.2, 12.0), true, "25/02/1578", "henrynou"); + henry.registerFidelityPlan("Point"); + henry.unregisterFidelityPlan(); + FidelityCard card = henry.getCard(); + assertTrue(card.returnType() == "Basic"); + + } + + @Test + public void testGetPointInTheCard() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + henry.registerFidelityPlan("Point"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + assertTrue(henry.getPointInTheCard() == 1); + } + + + @Test + public void testAcceptSpam() { + Customer henry = new Customer(0245, "henry", "henry", "henry.dupont@homtail.fr", "123456789", new Adress(10.2, 12.0), true, "25/02/1578", "henrynou"); + henry.setSpamAgree(false); + henry.acceptSpam(); + assertTrue(henry.isSpamAgree()); + } + + @Test + public void testRefuseSpam() { + Customer henry = new Customer(0245, "henry", "henry", "henry.dupont@homtail.fr", "123456789", new Adress(10.2, 12.0), true, "25/02/1578", "henrynou"); + henry.refuseSpam(); + assertTrue(henry.isSpamAgree() == false); + } + + @Test + public void testUpdate() { + fail("Not yet implemented"); + } + + +} diff --git a/src/test/TestManager.java b/src/test/TestManager.java new file mode 100644 index 0000000000000000000000000000000000000000..3c48fd489b7d3a4b58e15281cf6407d0dea8632e --- /dev/null +++ b/src/test/TestManager.java @@ -0,0 +1,268 @@ +package test; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; + +import Core.MyFoodora; +import DeliveryStrategy.ContextDeliveryStrategy; +import DeliveryStrategy.StrategyDeliveryPolicy; +import Exception.ExceptionUnknownDishType; +import Exception.ExceptionUnknownStartegyType; +import Item.Dish; +import Others.Adress; +import Others.Period; +import StrategyProfit.ContextTargetProfitStrategy; +import StrategyProfit.TargetProfitMarkup; +import User.Courier; +import User.Customer; +import User.Manager; +import User.Restaurant; +import User.User; +import UserFactoryPattern.FactoryUserFactory; +import UserFactoryPattern.UserFactory; + +public class TestManager { + + public static final int UNKNOWN = 0; + public static final int COURIER = 1; + public static final int RESTAURANT = 2; + public static final int CUSTOMER = 3; + public static final int MANAGER = 4; + + @Test + public void testAddUser() throws ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + boolean isIn = false; + for(Customer customer : foodora.getListCustomer().getList()){ + if(customer.getName() == "henry"){ + isIn = true; + } + } + assertTrue(isIn); + + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,null, null, foodora,RESTAURANT,"Moral"); + boolean isIn2 = false; + for(Restaurant restaurant : foodora.getListRestaurant().getList()){ + if(restaurant.getName() == "La tani�re"){ + isIn2 = true; + } + } + + assertTrue(isIn2); + + } + + @Test + public void testRemoveUser() throws ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + Customer henry = null; + for(Customer customer : foodora.getListCustomer().getList()){ + if(customer.getName() == "henry"){ + henry = customer; + } + } + manager.removeUser(henry, foodora); + boolean isNotIn = true; + for(Customer customer : foodora.getListCustomer().getList()){ + if(customer.getName() == "henry"){ + isNotIn = false; + } + } + assertTrue(isNotIn); + } + + @Test + public void testChangeServiceFee() throws ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.changeServiceFee(4.5, foodora); + assertTrue(foodora.getServiceFee() == 4.5); + } + + @Test + public void testGetTotalIncome() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + Others.Date begin = new Others.Date(2017, 04, 30); + Others.Date end = new Others.Date(2018, 12, 14); + Period period = new Period(begin, end); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + double totalIncome = manager.getTotalIncome(period, foodora); + assertTrue(totalIncome == 4.5); + } + + @Test + public void testGetTotalProfit() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + foodora.setMarkupPercentage(0.05); + foodora.setDeliveryCost(10); + foodora.setServiceFee(10); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + Others.Date begin = new Others.Date(2017, 04, 30); + Others.Date end = new Others.Date(2018, 12, 14); + Period period = new Period(begin, end); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 100); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + double totalProfit = manager.getTotalProfit(period, foodora); + assertTrue(totalProfit == 5.); + } + + @Test + public void testGetAverageIncomePerCustomer() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + Others.Date begin = new Others.Date(2017, 04, 30); + Others.Date end = new Others.Date(2018, 12, 14); + Period period = new Period(begin, end); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0146, "henry2", "henry2", "henry2.dupont@hotmail.fr", "1245789", new Adress(11.0, 15.3), true, "25/12/1995", "henrynou2", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 5.0); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + double averageIncomePerCustomer = manager.getAverageIncomePerCustomer(foodora, period); + assertTrue(averageIncomePerCustomer == 5.0); + } + + @Test + public void testSetTargetProfitPolicy() throws ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + ContextTargetProfitStrategy newStrategy = new ContextTargetProfitStrategy("ServiceFee"); + manager.setTargetProfitPolicy(foodora, newStrategy); + assertTrue(foodora.getContextTargetProfitStrategy().toString() == "ServiceFee"); + } + + @Test + public void testSetDeliveryPolicy() throws ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + ContextDeliveryStrategy newStrategy = new ContextDeliveryStrategy("FastestDelivery"); + manager.setDeliveryPolicy(foodora, newStrategy); + assertTrue(foodora.getContextDeliveryPolicy().toString() == "FastestDelivery"); + } + + @Test + public void testGetMostSellingRestaurant() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0245, "La tani�re2", "Lataniere2", "contact@lataniere2.fr", "12345", new Adress(10.0, 18.0), true,null, null, foodora,RESTAURANT,"Moral"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + String mostSellingOne = manager.getMostSellingRestaurant(foodora); + assertTrue(mostSellingOne == "La tani�re"); + } + + @Test + public void testGetLeastSellingRestaurant() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + manager.addUser(0245, "La tani�re2", "Lataniere2", "contact@lataniere2.fr", "12345", new Adress(10.0, 18.0), true,null, null, foodora,RESTAURANT,"Moral"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + String mostSellingOne = manager.getLeastSellingRestaurant(foodora); + assertTrue(mostSellingOne == "La tani�re2"); + } + + @Test + public void testGetLeastActiveCourier() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + manager.addUser(0246, "martin2", "martin2", "martin2.zebre@hotmail.fr", "12345", new Adress(10.0, 18.0), true,"25/12/1945", "martinou2", foodora,COURIER,"Human"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + Courier martin = (Courier) foodora.getUserByName("martin", "martin"); + Courier martin2 = (Courier) foodora.getUserByName("martin2", "martin2"); + String leastActiveCourier = manager.getLeastActiveCourier(foodora); + assertTrue(leastActiveCourier == "martin"); // pb + } + + @Test + public void testGetMostActiveCourier() throws ExceptionUnknownStartegyType, ExceptionUnknownDishType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0245, "martin", "martin", "martin.zebre@hotmail.fr", "1234", new Adress(10.0, 18.0), true,"25/12/1945", "martinou", foodora,COURIER,"Human"); + manager.addUser(0246, "martin2", "martin2", "martin2.zebre@hotmail.fr", "12345", new Adress(10.0, 18.0), true,"25/12/1945", "martinou2", foodora,COURIER,"Human"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + ArrayList<String> command = new ArrayList<String>(); + command.add("pat�"); + henry.placeOrder(resto1, "Dish", command, foodora); + String mostActiveCourier = manager.getMostActiveCourier(foodora); + assertTrue(mostActiveCourier == "martin2"); + } + + @Test + public void testActivateUser() throws ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + henry.setActivated(false); + manager.activateUser(foodora, henry); + assertTrue(henry.isActivated()); + } + + @Test + public void testDesactivateUser() throws ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0145, "henry", "henry", "henry.dupont@hotmail.fr", "124578", new Adress(11.0, 15.2), true, "25/12/1994", "henrynou", foodora, CUSTOMER, "Human"); + Customer henry = (Customer) foodora.getUserByName("henry", "henry"); + henry.setActivated(true); + manager.desactivateUser(foodora, henry); + assertTrue(henry.isActivated() == false); + + } + +} diff --git a/src/test/TestRestaurant.java b/src/test/TestRestaurant.java new file mode 100644 index 0000000000000000000000000000000000000000..03de4a1eca9fe875ef30a16f9f333d859aa269f7 --- /dev/null +++ b/src/test/TestRestaurant.java @@ -0,0 +1,153 @@ +package test; + +import static org.junit.Assert.*; + +import java.util.ArrayList; + +import org.junit.Test; + +import Core.MyFoodora; +import Exception.ExceptionUnknownDishType; +import Exception.ExceptionUnknownMealType; +import Exception.ExceptionUnknownStartegyType; +import Item.Dish; +import Item.HalfMeal; +import Item.Meal; +import Others.Adress; +import User.Manager; +import User.Restaurant; + +public class TestRestaurant { + + public static final int UNKNOWN = 0; + public static final int COURIER = 1; + public static final int RESTAURANT = 2; + public static final int CUSTOMER = 3; + public static final int MANAGER = 4; + + @Test + public void testAddMeal() throws ExceptionUnknownDishType, ExceptionUnknownMealType { + Restaurant resto = new Restaurant(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true); + resto.addDish("MainDish", "pat�", "glutenfree", 4.5); + resto.addDish("Starter","boulgour","vegetarian", 5); + resto.addDish("Dessert", "fondant", "regular", 7); + Dish pat� = resto.getDishByName("pat�"); + Dish boulgour = resto.getDishByName("boulgour"); + Dish fondant = resto.getDishByName("fondant"); + resto.createMeal("meal1", "FullMeal"); + Meal meal1 = resto.getMealByName("meal1"); + resto.addDishToMeal(fondant, meal1); + resto.addDishToMeal(boulgour, meal1); + resto.addDishToMeal(pat�, meal1); + boolean isIn = false; + for(Meal m : resto.getListOfMeal()){ + if(m.getName() == "meal1"){ + isIn = true; + } + } + assertTrue(isIn); + + } + + @Test + public void testAddDish() throws ExceptionUnknownDishType { + Restaurant resto = new Restaurant(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true); + resto.addDish("MainDish", "pat�", "glutenfree", 4.5); + boolean isIn = false; + for(Dish d : resto.getListOfDish()){ + if(d.getName() == "pat�"){ + isIn = true; + } + } + + assertTrue(isIn); + } + + @Test + public void testRemoveMeal() throws ExceptionUnknownDishType, ExceptionUnknownMealType { + Restaurant resto = new Restaurant(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true); + resto.addDish("MainDish", "pat�", "glutenfree", 4.5); + resto.addDish("Starter","boulgour","vegetarian", 5); + resto.addDish("Dessert", "fondant", "regular", 7); + Dish pat� = resto.getDishByName("pat�"); + Dish boulgour = resto.getDishByName("boulgour"); + Dish fondant = resto.getDishByName("fondant"); + resto.createMeal("meal1", "FullMeal"); + Meal meal1 = resto.getMealByName("meal1"); + resto.addDishToMeal(fondant, meal1); + resto.addDishToMeal(boulgour, meal1); + resto.addDishToMeal(pat�, meal1); + resto.removeMeal(meal1); + boolean isIn = false; + for(Meal m : resto.getListOfMeal()){ + if(m.getName() == "meal1"){ + isIn = true; + } + } + assert(isIn == false); + } + + @Test + public void testRemoveDish() throws ExceptionUnknownDishType { + Restaurant resto = new Restaurant(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true); + resto.addDish("MainDish", "pat�", "glutenfree", 4.5); + Dish pat� = resto.getDishByName("pat�"); + resto.removeDish(pat�); + boolean isIn = false; + for(Dish d : resto.getListOfDish()){ + if(d.getName() == "pat�"){ + isIn = true; + } + } + assertTrue(isIn == false); + } + + @Test + public void testGetSortListOfHalfMeal() throws ExceptionUnknownDishType, ExceptionUnknownMealType { + Restaurant resto = new Restaurant(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true); + resto.addDish("MainDish", "pat�", "glutenfree", 4.5); + resto.addDish("Starter","boulgour","vegetarian", 5); + resto.addDish("Dessert", "fondant", "regular", 7); + Dish pat� = resto.getDishByName("pat�"); + Dish boulgour = resto.getDishByName("boulgour"); + Dish fondant = resto.getDishByName("fondant"); + resto.createMeal("meal1", "FullMeal"); + Meal meal1 = resto.getMealByName("meal1"); + resto.addDishToMeal(fondant, meal1); + resto.addDishToMeal(boulgour, meal1); + resto.addDishToMeal(pat�, meal1); + resto.createMeal("meal1", "HalfMeal"); + Meal meal2 = resto.getMealByName("meal1"); + resto.addDishToMeal(fondant, meal2); + resto.addDishToMeal(boulgour, meal2); + for(Meal m : resto.getListOfMeal()){ + if(m.getName() == "meal1"){ + m.setNbOfSell(20); + } + } + ArrayList<HalfMeal> sortList = resto.getSortListOfHalfMeal(); + HalfMeal mostSelled = sortList.get(0); + assertTrue(mostSelled.getName() == "meal1"); + } + + @Test + public void testGetSortListOfDish() throws ExceptionUnknownDishType, ExceptionUnknownStartegyType { + MyFoodora foodora = new MyFoodora(); + Manager manager = new Manager(0674, "jacques", "jacquo", "jacques.martin@hotmail.fr", "123456789", new Adress(15.0, 10.0), true, "25/15/1955", "jacquo"); + manager.addUser(0245, "La tani�re", "Lataniere", "contact@lataniere.fr", "1234", new Adress(10.0, 15.0), true,"1", "1", foodora,RESTAURANT,"Moral"); + Restaurant resto1 = (Restaurant) foodora.getUserByName("Lataniere", "La tani�re"); + resto1.addDish("MainDish", "pat�", "glutenfree", 4.5); + resto1.addDish("Starter","boulgour","vegetarian", 5); + ArrayList<Dish> cartOfRestaurant = resto1.getListOfDish(); + for(Dish dish : cartOfRestaurant){ + if(dish.getName() == "pat�"){ + dish.setNbOfSell(20); + } + } + ArrayList<Dish> sortList = resto1.getSortListOfDish(); + Dish mostSelled = sortList.get(0); + assertTrue(mostSelled.getName() == "pat�"); + + } + +} diff --git a/src/test/main.java b/src/test/main.java deleted file mode 100644 index df842925f6db3e9119b626432e31fd91cc579ea8..0000000000000000000000000000000000000000 --- a/src/test/main.java +++ /dev/null @@ -1,19 +0,0 @@ -package test; - -import Cards.BasicFidelityCard; -import Cli.Clui; -import Core.MyFoodora; -import Exception.ExceptionUnknownStartegyType; -import Others.Adress; -import User.Courier; - -public class main { - - public static void main(String[] args) throws ExceptionUnknownStartegyType { - MyFoodora foodora = new MyFoodora(); - Clui clui = new Clui(foodora); - } - - } - -