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

changes done

parent 41a1c651
No related branches found
No related tags found
No related merge requests found
Showing
with 537 additions and 54 deletions
......@@ -7,6 +7,7 @@ public abstract class FidelityCard implements VisitableCard {
protected long id;
public FidelityCard (){
IDCard idCard = IDCard.getInstance();
this.id = idCard.getNextSerialNumber();
......
......@@ -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;
}
}
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.");
}
if (isIn = false){
System.out.println("this command is not possible");
}catch (errorWrongNumberOfParams ex) {
System.out.println(ex);
}
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);
}
}
}
......@@ -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 paramtre.
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);
}
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
}
}
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
}
}
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
}
}
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 o er\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 pro t 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");
}
}
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);
}
}
}
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 !");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
......@@ -7,6 +7,7 @@ public class ActiveUserContext {
User activeUser;
public ActiveUserContext(MyFoodora foodora) {
// TODO Auto-generated constructor stub
activeUser = null;
}
public User getUser(){
return activeUser;
......
......@@ -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);
}
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 tanire", "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 tanire");
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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment