diff --git a/build.gradle b/build.gradle index fa65ffac..977bf182 100644 --- a/build.gradle +++ b/build.gradle @@ -13,18 +13,27 @@ repositories { } shadowJar { - archiveBaseName = "mid" - archiveVersion = "v1.1" + archiveBaseName = null + archiveVersion = "v1.3" archiveClassifier = null archiveAppendix = null } +sourceSets{ + main { + resources { + srcDirs = ['src/main/java'] + } + } +} + checkstyle { toolVersion = '8.23' } dependencies { testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0' + compile group: 'com.massisframework', name: 'j-text-utils', version: '0.3.4' } test { diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index f549f834..a2691049 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -47,7 +47,7 @@ - + diff --git a/data/fridge.txt b/data/fridge.txt index 541d8f21..a9d68dde 100644 --- a/data/fridge.txt +++ b/data/fridge.txt @@ -1,6 +1,14 @@ -cheese|2|12/10/2019 +<<<<<<< HEAD +milk|3|09/09/09 cheese|4|12/12/2019 rice|50|12/12/2019 +======= +somethingsomeone|50|23/12/2019 +>>>>>>> upstream/master potato|3|12/2/2020 +rice|500|2/3/2020 rice|250|2/3/2020 rice|500|12/12/2020 +cheese|100|30/10/2019 +rice|501|12/10/2019 +rice|503|12/10/2019 diff --git a/data/order.txt b/data/order.txt new file mode 100644 index 00000000..e69de29b diff --git a/data/tasks.txt b/data/tasks.txt index b1077cc7..81dbb353 100644 --- a/data/tasks.txt +++ b/data/tasks.txt @@ -1,8 +1,12 @@ T|1|read book -D|1|return book|09/09/09 2359 -T|1|beef 16/10/2019 +T|0|beef 16/10/2019 T|0|test 09/09/09 T|1|test1 16/10/2019 T|0|read books T|0|sleep -T|0|homeworrk 12/12/2019 +<<<<<<< HEAD +T|0|sleep +milk|2|null +======= +>>>>>>> upstream/master +T|0|beef 24/10/2019 diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index f44f9b48..42929c6b 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -13,6 +13,13 @@ 7. Exception Component 8. Recipebook Component 9. RecipeCommand Component + 10. Order Component + 11. OrderCommand Component + 12. Fridge Component + 13. GenericList + 14. Ingredient + 15. ingredientCommand Component + 16. Statistics 3. Implementation @@ -46,18 +53,25 @@ #### 2.1 Architecture -![architecture]( https://github.com/AY1920S1-CS2113-T14-2/main1/blob/master/docs/images/architectureV1.1.png ) +![architecture]( https://github.com/AY1920S1-CS2113-T14-2/main1/blob/master/docs/images/archh.png ) `main` has 1 class called `Duke`. It is responsible for, - at app launch: Loads all the data in storage into the application, initialize the components, reads the commands and executes them correctly. - at shut down: shuts down all component and exits the application -The Application consist of 6 other components +The Application consist of 11 other components - `command`: executes the command that is read from the user - -- `exception`: handle error messages +- `dishesCommand` + - `orderCommand` + - `ingredientCommand` +- `exception`: handle error messages +- `dish`: contains the dishlist as well the the dish class +- `fridge`: contains +- `ingredient`: contains ingredient list +- `list`: a class which contains a generic list. this list is used by various other classes +- `order`: - `parser`: determine the next course of action from the user command - `storage`: Reads, writes data from and to the hard disk - `task`: stores a list of deadline/event/todo that needs to be done @@ -98,21 +112,39 @@ The Ui will reply to the User with the following messages: The Ui class consists of methods that outputs messages to the user as a response when the user enters a certain command - reads and return s user input using `scanner.nextLine()` -- outputs messages to the user as a response such as `showAddCommand`, `showRemoveCommand`, etc +- outputs messages to the user as a response such as `AddDishCommand ` `DeleteDishCommand`, etc #### 2.3 Command Component API: `Command.java` -The Command class is used as an abstract class for other classes, its method `execute` is also declared as an abstract method that is used by the following classes - -- DoneCommand -- ExitCommand -- FindCommand -- ListCommand -- RemindCommand -- Snooze -- ViewCommand +In the project, it has three types of commands: Ingredient Command, Dishes Command, Order Command. The three types of commands are packaged separately. + +The Command class is used as an abstract class for other classes, its method `execute` is also declared as an abstract method. that is used by the following classes + +- DishCommand + - AddDishCommand + - DeleteDishCommand + - ListDishCommand + - InitCommand + - AddIngredient +- OrderCommand + - AddOrderCommand + - AlterOrderCommand + - DeleteOrderCommand + - DoneOrderCommand + - ListOrderCommand +- IngredientCommand + - AddCommand + - DeleteCommand + - DoneCommand + - ExitCommand + - FindIngredientCommand + - FindToday + - ListCommand + - RemoveAllExpired + - UseCommand + - ViewCommand each of the above class has its own implementation of the `execute` method @@ -120,14 +152,19 @@ each of the above class has its own implementation of the `execute` method API: `Parser.java` +makes sense of the data that is read by the user from the Duke Class. +this component gets the command from the user through the Duke Class. This component will then make sense of the command by splitting the command into different parts as well as determining the command type. +depending on the content of the splitted value and command type, Parser class will execute different commands. #### 2.5 Storage Component API: `Storage.java` + + This component stores entries in a certain format, tasks, ingredients that are already in the Fridge, and anything else that needs to be saved on the hard disk. -It is modeled as an abstract class, with `TaskStorage.java` and `FridgeStorage.java` both inheriting from it. It allows data (tasks in the list, ingredients in the fridge, recipes in the recipeBook...) to be saved and remembered by our program. +It is modelled as an abstract class, with `TaskStorage.java` and `FridgeStorage.java` both inheriting from it. It allows data (tasks in the list, ingredients in the fridge, recipes in the recipe Book...) to be saved and remembered by our program. An example for the format of saving for tasks is : @@ -140,7 +177,9 @@ where the first column is denotes the type of task, T for todo, D for deadline, The program can `load` or `generate` an entry from the storage and also `changeContent` and `addInFile` -![Storage](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/StorageUML.png) + +![Storage](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/StorageUML1.png) + #### 2.6 Task Component @@ -154,99 +193,267 @@ API: `DukeException.java` #### 2.8 Dishes Component -The Recipebook contains 2 classes, Dishes Class and DishList Class. The Dishes Class +The Recipebook contains 2 classes, Dishes Class and DishList Class -![Dishes](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/dishes%20diagram.png) +![dishes](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/dishes.PNG) **Dishes Class** -| Attributes | Description | -| ---------------------------- | ----------------------------------------------- | -| dishName: String | name of the dish | -| total: int | the total number of orders for that dish | -| rating: float | the overall rating for that dish | -| ingredientList: List | a list of ingredients associated with that dish | - +This class holds the name of the dish as well the ingredients that are associated to that specific dish. +| Attributes | Description | +| -------------------------------- | ----------------------------------------------- | +| dishName: String | name of the dish | +| numberOfOrders: int | the total number of orders for that dish | +| rating: float | the overall rating for that dish | +| ingredientList: `IngredientList` | a list of ingredients associated with that dish | | Constructor | Description | | -------------- | ---------------------------------------- | | Dishes(String) | assigns the name of the dish with String | +| Methods | Description | +| ---------------------------- | ------------------------------------------------------------ | +| clearOrders(): void | clears the ingredient list | +| getDishName(): String | returns the name of the dish | +| addIngredients(String): void | takes a string and adds into ingredientlist | +| toString(): String | it returns a String of all the ingredients that the dish contains | +**DishList Class** +this class inherits the GenericList class which takes in a List of Dish. this class holds all the dishes that is stored in the csv file thus this acts as a menu for the chef -| Methods | Description | -| ----------------------------- | ------------------------------------------------------------ | -| getTotalNumberOfOrders(): int | returns `total` which is an int | -| setNumberofOrders(int): void | takes in an `int` and increment `total` number of orders | -| clearOrders(): void | clears the ingredient list | -| getDishName(): String | returns the name of the dish | -| setRating(int): void | takes in an `int` and sets the new overall rating of the dish | -| getRating(): float | returns the rating of that dish | -| addIngredients(String): void | takes a string and adds into ingredientlist | +| Constructor | Description | +| -------------------- | ------------------------------------------ | +| DishList(List) | assigns a list of dishes to dishList | +| DishList() | assigns an empty ArrayList<>() to dishList | -**DishList Class** -| Atrributes | Description | -| ---------------------- | ----------- | -| dishList: List | | +#### 2.9 dishesCommand Component + +The dishesCommand component enables the chef to modify the dishList which acts as a menu or recipebook. this component inherits from other classes. + +- addDishCommand and addIngredient inherits from AddCommand class which inherits from the Cmd class +- deleteDishCommand inherits from the DeleteCommand which inherits from the Cmd class +- ListDishCommand and InitCommand inherits from the Cmd class + +this component allows the chef to add dishes to the current menu, remove it and also to see the menu in the form of a list. this component also allows the chef to initialize his menu which deletes all entries in the dishList. the chef is also able to add ingredients to a specific dish in the dishList. + +- **AddDishCommand** + + user enters the command `addish chicken rice /num 2` which denotes adding the dish called chicken rice into the dishList. the program will enter the AddDishCommand class and executes the method below. + + ```java + if(dishList.size() == 0) { + dishList.addEntry(dish); + dishList.getEntry(0).setNumberOfOrders(amount); + ui.showAddedDishes(dish.getDishname(), amount); + } + ``` + + + + If the dishList is empty(size of dishList is 0), immediately add the dish into the dishList. however, if the dishList is not empty, the program will need to go through the entire dishList to check if the dish has already been added. this is done so that there are no duplicate dishes. + + + + once the dish is added to the dishList, the method will use the Ui class with method call ui.showAddedDishes() as a reply to the user that the dish has been successfully added into the list. + + + +- **AddIngredient** +- **DeleteDishCommand** -| Constructor | Description | -| ----------- | ------------------------------------------------- | -| DishList() | initalize the empty dishLIst as a new ArrayList<> | +- **InitCommand** +- **ListDishCommand** +![dishesCommand](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/dishesCommand.PNG) -| Methods | Description | -| ------------------------ | ----------- | -| addDishes(Dishes): void | | -| deleteDish(int): void | | -| getDish(int): Dishes | | -| getSize(): int | | -| clearList(): void | | -| toString(Dishes): String | | +**future additions** +#### 2.10 Order Component +API: `Order.java`, `OrderList.java` + +The Order component contains 2 classes, Order Class and OrderList Class. The chef can add new orders and update his "todo list" today. When an order comes, the program calculates dishes amount for each type of dishes. It then access the recipebook which contains every dishes in the menu including the recipe (the amount of consisting ingredients) so as to get the total amount of the ingredients needed to finish this order. It checks with the storage of those ingredients in the fridge and returns the information that if ingredients are enough. + +Besides, in current stage, we assume that the dishes in chef's todo list should be finished by the end of "today". At the beginning of every day, the todo list will be initialized. However, the order supports pre-order, allowing the order date is not today. That is, the initialization of chef's todo list might not be empty. + + +**Order Class** + +| Attributes | Description | +| --------------------------------------------------- | ------------------------------------------------------------ | +| content: Map | the content of the order, specifying ordered dishes and amount | +| isDone: boolean | the status of the order: *true* if done, *false* otherwise | +| date: Date | the serving date of the order (not the date when the order was created) | + + + +| Constructor | Description | +| ------------- | ------------------------------------------------------------ | +| Order() | By default, the order is not done; the serving date is today. | +| Order(String) | Assigns the serving date of the order with String. Call if it is a pre-order. | + + + +| Methods | Description | +| -------------------------------------- | ------------------------------------------------------------ | +| getDate(): Date | returns the serving `date` of the order | +| setDate(String): void | takes in a `String` and alter the serving `date` of the order | +| isToday(): boolean | returns a `boolean` indicating whether the serving date is today or not | +| isDone(): boolean | returns a `boolean` indicating whether the order is finished or not | +| markAsDone(): void | mark the order as finished | +| getStatusIcon(): String | takes in an `int` and sets the new overall rating of the dish | +| getOrderContent(): Map | returns the order content as `Map` | +| toString(): String | returns description of the order as `String` | +| printInFile(): String | returns description of the order that used to store in the txt file | +| hasDishes(Dishes): boolean | returns a `boolean` indicating whether the order has the dishes or not | +| getDishesAmount(Dishes): int | returns the amount of the query dishes in the order | +| addDish(Dishes): void | add one more the dishes to the undone order | +| addDish(Dishes, int): void | add the dishes to the undone order with adding amount | + +**OrderList Class** + +| Atrributes | Description | +| ---------------------- | ----------- | +| orderList: List | | -#### 2.9 RecipeCommand Component -The RecipeCommand class is used as an abstract class for other classes, its method `execute` is also declared as an abstract method that is used by the following classes +| Constructor | Description | +| ---------------------- | -------------------------------------------------- | +| OrderList() | initalize the empty orderLIst as a new ArrayList<> | +| OrderList(List) | Assign a list of orders to the orderList | -- AddDishCommand -- AddIngredient -- DeleteDishCommand -- InitCommand -- ListDishCommand -![DishesCommand](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/dishesCommand%20diagram.png) -#### 2.10 Fridge Component +| Methods | Description | +| ------------------------------------ | ------------------------------------------------------------ | +| size(): int | returns the number of orders in the orderList | +| markOrderDone(int): void | mark a order as completed | +| getOrder(int): Order | return the order at the position indexed by number | +| getAllUndoneOrders(): List | return all undone orders in the orderList | +| getTodayOrders(): List | return all today's orders in the orderList | +| getTodayUndoneOrders(): List | return all today's orders which is undone in the orderList | +| findOrderByDate(String): List | returns a list of orders on that date | +| findOrderByDishes(Dish): List | returns a list of orders that contains that dishes | +| changeOrderDate(int, String): void | alter the serving date of the order in the orderList | +| getDishesTodayAmount(Dishes): int | return required amount of the dishes that needed to be done before the end of today | +| addOrderDish(int, Dishes): void | add dishes to the order in the orderList | +| addOrderDish(int, Dishes, int): void | add dishes with amount to the order in the orderList | +| findDishesAmont(int, Dishes): int | find dishes amount in the order among the orderList | + +#### + +#### 2.11 Order Command Component +API: `AddOrderCommand.java`, `AlterDateCommand.java`, `DeleteOrderCommand.java`, `DoneOrderCommand.java`, `ListOrderCommand.java` + +The Order Command classes inherits from the `Command` class. They overwrite the abstract method `execute` of the `Command` class. The Order Command classes includes: + +- AddOrderCommand: This command will add order to the orderlist and update the chef's todo list. The order can be loaded manually by command. The order can also be read from the file when initializing -- which is the case of the pre-order. +- AlterDateCommand: This command will change the serving date of the order. If it changed to the date of today, then chef's todo list should be updated. If it changed to the date before today, then the change is considered invalid. +- DeleteOrderCommand: This command is used for cancelled orders. It also synchronizes with chef's todo list. +- DoneOrderCommand: This command is used for changing the status of the order to be finished. The done dishes in the order can be removed from the chef's todo list. +- ListOrderCommand: The command is to list all orders or is to list orders after filtering. The filter feature can be date, dishes, order status. + +#### 2.12 Fridge Component API: `Fridge.java` The Fridge class allows access and modification of the `Ingredient`s used by the chef. By keeping track of the Ingredients' expiry date, it allows the user to know which products have expired, and remove them. It allows for less ingredient waste, as it can return the most recently expiring ingredients, so that they can be used first. -![Fridge](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/fridgeUML.png) +![Fridge](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/fridgeUML1.png) -#### 2.11 GenericList +#### 2.13 GenericList +API: `GenericList.java` This abstract class allows for creation of different types of lists, and basic list entry manipulations. It is extended by multiple classes, including `IngredientsList.java`, `TaksList.java`, `OrderList.java` and `DishList.java`. All of these classes inherit the basic methods from the Generic List and extend it with their specific methods, eg. `allUndoneOrders()` from`OrderList.java`, or `changeAmount()` from `IngredientsList.java`. A UML Class Diagram is shown below. -![GenericList](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/GenericListUML.png) +![GenericList](https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/images/GenericListUML1.png) -### 3. Implementation +#### 2.14 Ingredient Component +The Recipebook contains 2 classes, Ingredient and IngredientsList. +//!add diagram of the Ingredient component. -### 4. Documentation +**Ingredient Class** +| Attributes | Description | +| -------------------- | -------------------------------------- | +| name: String | Name of the ingredient | +| amount: int | Total amount of the ingredient | +| expiryDate: Date | Expiry date of the given ingredient | +| dateAsString: String | A string to store the date as a string | -### 5. Testing +##### Ingredient Class + +| Constructor | Description | +| --------------------------------- | --------------------------------------------------------- | +| Ingredient(String, Integer, Date) | Gives the name , amount and expiry date of the ingredient | + + + +| Methods | Description | +| ----------------------------------- | ------------------------------------------------------------ | +| Ingredient(String, Integer, String) | Converts the Date into String | +| getAmount(): int | Returns amount of ingredient | +| getName(): String | Returns name of the Ingredient | +| changeDate(Date): void | Changes the expiry date of the ingredient | +| setName(String): void | Sets the name of the ingredient | +| changeAmount(Integer): void | Changes the amount of the ingredient | +| getExpiryDate(): Date | Returns the expiry date of the ingredient | +| equals(Object): Boolean | Returns true or false when comparing 2 objects
True: Object names are identical
False: Otherwise | +| isExpired(): Date | Returns the expiry date | +| equalsCompletely(Object): Boolean | Returns true or false when comparing 2 objects
True: Objects have same name and expiry date
False: Otherwise | + +**IngredientsList Class** + +A child class of Ingredients and inherits(extends) the attributes and methods of the Ingredients class. + +| Constructor | Description | +| ------------------------------------------------- | --------------------------------------------------------- | +| IngredientsList(List ingredientsList) | Initializes the IngredientsList as a new List | + + + +| Methods | Description | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| changeIngredientsDate(int, Date): void | Changes the date of the Ingredient using an Index number | +| changeName(int, String): void | Changes the name of the ingredient using an Index number | +| changeAmount(int, String): void | Changes the amount of the ingredient using an index number | +| addEntry(Ingredient Object): void | Adds a new Ingredient of Ingredients attributes into the Ingredient List | +| hasEnough(Ingredient Object): Boolean | Returns true or false when comparing 2 Objects.
True: We have enough of the required Ingredient
False: Otherwise | +| getEntry(Ingredient Object): Ingredient Object | Looks for the queried ingredient and returns it | +| getNonExpiredEntry(Ingredient ingredient): Ingredient Object | Looks for the queried Ingredient in the list that is not expired and returns it | +| sortByExpiryDate(): Ingredient Object | Sorts the Ingredient lists accordingly by a descending amount | +| removeEntry(Ingredient Object): Boolean | Looks for the queried Ingredient in the list and remove the amount that we want to use.
True: Enough amount of the queried ingredient
False: Not enough amount of the queriedingredient | + +#### 2.15 ingredientCommand Component + +API: `AddCommand.java`, `DeleteCommand.java`, `FindToday.java`, `ListCommand.java`, `RemoveAllExpired.java,FindIngredientCommand.java, UseCommand.java,` + +The ingredientCommand classes inherits from the `Command` class. They overwrite the abstract method `execute` of the class `Cmd`. The ingredientCommand classes includes: + +- AddCommand: This command adds an entry of an ingredient to the IngredientsList. The IngredientsList can also be read from the file when initializing. +- DeteleCommand: This command deletes an entry of an ingredient from the IngredientsList. +- FindToday: This command is used to look for expired ingredients on the date itself. +- ListCommand: This command is used to show the chef's entire IngredientsList. +- RemoveAllExpired: The command is used to remove all expired ingredients from the IngredientsList +- FindIngredientCommand: This command is used to find all ingredients with the queried keyword entered by the chef. +- UseCommand: This command is used to delete the specified amount off an ingredient when it is used. Otherwise, if there is not enough of the required amount entered by the chef, the program will prompt it to the chef. + +### 3. Implementation + +### 4. Documentation + +### 5. Testing + ### 6. Dev Ops @@ -423,7 +630,6 @@ Target user profile: Restaurant Chef 3. should be reliable in displaying accurate and correct data 4. should be easy to use for users with basic knowledge of command line interface 5. should be able to handle large amounts of data without displaying any slowdown in application performance -6. diff --git a/docs/UserGuide.md b/docs/UserGuide.md index dc72c348..6dc8aead 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -3,12 +3,12 @@ 1. Introduction 2. Quick Start 3. Features - - bye: Exit the program - - list: Show all the tasks - - done: Mark a task as done - - todo: Create a new todo task - - deadline: Create a new deadline task - - event: Create a new event task + - Menu + - Adding Dish + - Adding Ingredient to Dish + - List all Dish + - Initialize Dish + - Removing Dish - Load and save tasks to hard disk - Identify dates and times - delete: Delete a task @@ -19,7 +19,7 @@ ## 1. Introduction -Duke is targeted towards restaurant chefs who wants to be able to consolidate most of the things happening in their kitchen such as recipes, ingredients, expiry dates etc. By using this product, you are able to order all the ingredients needed for your kitchen. Additionally, this application takes in customers order/preorder of the restaurants dishes. The customers are able to give their feedback/rating of the dishes. the average rating of all the dishes can be viewed by the restaurant chef. Proceed to the Developer Guide [here]( https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/DeveloperGuide.md ) to learn more about this application. +Duke is targeted towards restaurant chefs who wants to be able to consolidate most of the things happening in their kitchen such as recipes, ingredients, expiry dates etc. By using this product, you are able to order all the ingredients needed for your kitchen. Additionally, this application takes in customers order/preorder of the restaurants dishes. Proceed to the Developer Guide [here]( https://github.com/AY1920S1-CS2113-T14-2/main/blob/master/docs/DeveloperGuide.md ) to learn more about this application. @@ -31,121 +31,327 @@ Duke is targeted towards restaurant chefs who wants to be able to consolidate mo 3. Copy the file to the folder you want to use as the home folder for your Duke application. -4. Double-click the file to start the app. The GUI should appear in a few seconds. +4. Use the command prompt and navigate to the path where the application is downloaded + +5. run the command `java -jar v1.3` , application will then be executed ![UI]( https://github.com/AY1920S1-CS2113-T14-2/main1/blob/master/docs/images/Ui.png ) -5. Type into the INPUT box some commands and press ENTER to execute +6. Type some commands and press ENTER to execute -6. Some example commands +7. Some example commands - 1. **list**: lists out all the tasks - 2. **deadline** prepare new recipe **/by** 1/1/2019: adds a deadline task "prepare new recipe" into your list by "1/1/2019" - 3. **bye**: exits the program + 1. given various options in menu, user can type these commands`option` ,`q`, `a`, `b`, `c`, `d`. + 2. user enters `d` then `add chicken rice`, dish is then added to the list + 3. user enters `d` then `list`, outputs the the dishes and the ingredients associated to the dish in table form -7. Refer to Section 4 for the full list of commands +8. Refer to Section 4 for the full list of commands ## 3. Features **command format** -- commands are in `UPPER_CASE` are to be provided by the user eg. `todo d/DESC`, `DESC` is a parameter which can be used as `todo d/buy groceries` -- +- commands are in `UPPER_CASE` are to be provided by the user eg. `add/DESC`, `DESC` is a parameter which can be used as `add noodle`. + +### 3.1 Main Menu + +the user is greeted depending on the time of day, `good morning` , `good evening` etc. Upon start up, if there are any expired ingredients in the fridge, the application will prompt the user to clear the expired ingredients. In the Main menu, the user is given various options to enter: + +- `q` , **exits** the application +- `a`, remove the **expired** ingredients +- `b` , proceed to **fridge** commands +- `c`, proceeds to **order** commands +- `d`, proceeds to **dish** commands + +### 3.2 Adding Dish: `add` + +user needs to enter `d` in main menu first. + +To add a dish to the DishList, user needs to execute command below: + +Format: `add d/DESC` + +if the dish already exist in the list, message is output: + +``` + dish already exist in list +``` + +Examples: + +- `add chicken rice` +- ``add tom yum noodles` + +``` + _________________________________________________________________________________________ + you have added the following dish: + chicken rice + _________________________________________________________________________________________ +``` + + + +### 3.3 Adding Ingredient to Dish: `ingredient` + +user needs to enter `d` in main menu first. + +Executing this command associates an ingredient to a certain Dish. user needs to execute the command below: + +Format: `ingredient d/DESC n/AMOUNT i/INDEX` + +Examples: + +- `ingredient rice 50 1`, ingredient rice (50g) is now associated to 1st dish +- `ingredient noodle 50 2` ingredient noodle (50g) is now associated to 2nd dish + +``` + _________________________________________________________________________________________ + ingredient: rice + added to: chicken rice + _________________________________________________________________________________________ +``` + + + +### 3.4 List all Dishes: `list` + +user needs to enter `d` in main menu first. + +user needs to enter the command below: + +Format:`list` + +if there are no dishes in list, output message: + +``` + OOPS!!! No Dishes yet!. + You can type: + 'template' to see the format of the commands, + 'back' to see all your options, + 'q' to exit +``` + +if user enters a valid command, + +``` + ____________________________ + | Dish | ingredient| + |===========================| +1. | chicken rice | | +2. | chicken noodle| | +3. | pizza | | +4. | aglio olio | | +``` + + + +``` + _______________________________ + | Dish | ingredient | + |==============================| +1. | chicken rice | rice,salt, | +2. | chicken noodle| noodle,flour,| +``` + + + + +### 3.5 Initializing the Dish List:`initialize` + +user needs to enter `d` in main menu first. + +user needs to enter the command below: + +Format: `initialize` + +user is then asked to confirm as this command deletes all the entries in the dish + +if user enters yes, + +``` + are you sure you want to clear list? (yes or no) +yes + LIST IS CLEARED +``` + +if user enters no, + +``` + are you sure you want to clear list? (yes or no) +no + LIST IS NOT CLEARED +``` + + +### 3.6 Removing Dish:`remove` + +user needs to enter `d` in main menu first. + +user needs to enter the command below: + +Format: `remove i/INDEX` + +Examples: + +- `remove 1` +- `remove 2` + +if user enters an invalid index, a error message will appear + +``` + OOPS!!! dish does not exist. + You can type: + 'template' to see the format of the commands, + 'back' to see all your options, + 'q' to exit + _________________________________________________________________________________________ +``` + +if user enters a valid command, -### 3.1 bye: Exits the program +``` + _________________________________________________________________________________________ + The following dish have been removed: + chicken rice + _________________________________________________________________________________________ +``` + +### 3.7 Adding Ingredient + +User needs to enter `b` in the menu first. To add an ingredient to the IngredientsList, user needs to execute command below: + +Format: `add ` `ingredient name` `ingredient amount` `ingredient expiry date` -outputs an exit message to the user and terminates the program +if the ingredient already exist in the list, but **do not have the same expiry date**, another entry of the ingredient will be created in the ingredient list. **However**, if the ingredient also **have the same expiry date as the existing ingredient in the ingredient list**, the amount of the existing ingredient amount will be added on and no new entry will be created in the ingredient list. + +Examples: + +- `add ` `salt` `50` `31/10/2019` +- `add` `chilli` `70` `29/04/2019` + +``` + _________________________________________________________________________________________ + you have added the following ingredient: + salt 50 31/10/2019 + _________________________________________________________________________________________ +``` -Format: `bye` +### 3.8 Removing Ingredient -### 3.2 list: Show all the tasks +User needs to enter `b` in the menu first. To remove an ingredient from the IngredientsList, user needs to execute command below: -Shows all the task marked done/undone to the user +Format: `remove ` `ingredient index` + +if the ingredient index does not exist in the list, message is output: + +``` + ☹ OOPS!!! Enter a valid ingredient index number after delete, between 1 and 14. + You can type: + 'template' to see the format of the commands, + 'back' to see all your options, + 'q' to exit +``` + +this example was done when the size of the ingredient list is 14. + +Examples: + +- `remove ` `7` +- `remove` `3 ` + +``` + _________________________________________________________________________________________ + Noted. I've removed this ingredient: + salt, amount is: 50 expiring on 31st of Octoboer 2019 + Now you have 14 ingredients in the list. + _________________________________________________________________________________________ +``` -Format: `list` +### 3.9 Finding Ingredient -shows the user all the tasks that is stored in Duke +User needs to enter `b` in the menu first. To find an ingredient from the IngredientsList, user needs to execute command below: - Here are the tasks in your list: - 1.[D][✓] return book(by: Monday) - 2.[E][✘] meeting(at: U-Town) - 3.[P][✓] lecture(from: 1600 to: 1800) -### 3.3 done: Mark a task as done +Format: `find` `keyword` -marks a task in list as done. +if the ingredient index does not exist in the list, message is output: -Format: `done` +``` + No such ingredient found! +``` -eg. `done 1` +Examples: - Nice! I've marked this task as done: - [D][✓] return book(by: Monday) -### 3.4 todo: Create a new todo task +- `find ` `salt` +- `find` ` chilli ` -creates a new task, todo where user enters the description of the task that needs to be done +``` +These are the ingredients you searched for! + 5. salt 50 31/10/2019. + 9. salt 60 21/07/2021 +``` -Format: `todo` +### 3.10 Listing all expired ingredients on the date itself -eg. `todo order eggs` +User needs to enter `b` in the menu first. To list all expired ingredient from the IngredientsList on the date itself, user needs to execute command below: - Got it. I've added this task: - [T][✘] order eggs - Now you have 6 tasks in the list. -### 3.5 deadline: Create a new deadline task +Format: `listtoday` -creates a new task, deadline, where user enters their tasks as well the date that the task needs to be done +if there are no expired ingredients for the date itself, message is output: -Format: `deadline` `/by` +``` + No expired ingredients for today! +``` -eg. `deadline submit review /by 1/1/2019`, stores D|0|submit review|1/1/2019 +Otherwise, -output: +``` + Here are the expired ingredients for today + 6. salt, amount is: 50 expired on 31st of October 2019. + 7. chilli, amount is: 60 expired on 31st of October 2019. +``` - Got it. I've added this task: - [D][✘ ] submit review(by: 1/1/2019) - Now you have 5 tasks in the list. -### 3.6 event: Create a new event task +### 3.11 Removing all expired ingredients -creates a new task, event, where user enters their tasks as well the date that the task needs to be done +User needs to enter `a` in the menu. -Format: `event` `/at` +if there are no expired ingredients for the date itself, message is output: -eg. `event birthday /at multi purpose hall`, stores E|0|submit review|multi purpose hall +``` + ☹ OOPS!!! Seems like you don't have any expired ingredients in the fridge!. +``` -output: +Otherwise, - Got it. I've added this task: - [E][✘] birthday(at: multi purpose hall) - Now you have 4 tasks in the list. +``` + Removed: ingredients: +salt, amount is: 50 expired on 31st of October 2019 +``` +### 3.12 Using an ingredient -### 3.10 delete: Delete a task +User needs to enter `b` in the menu first. To use an ingredient from the IngredientsList, user needs to execute command below: -deletes a tasks that was stored in Duke regardless of it being marked as done or undone. +Format: `use` `ingredient name` `amount` -Format: `delete` +if there are not enough required ingredients, message is output: -eg. `delete 1`, deletes the first task that is stored in Duke +``` + There is not a sufficient amount of rice that is not expired, maybe you could buy some first? +``` -output: +Examples: - Noted. I've removed this task: - [T][✓] read book - Now you have 3 tasks in the list. -### 3.12 find: Find a task by searching for a keyword +- `use ` `salt` `50` +- `use` ` chilli` `40` -finds a task in Duke which contains a specific word or description +``` + Great you used salt amount: 50 +``` -Format: `find` +Also, once amount reaches 0, the ingredient will be deleted off from the IngredientsList. -eg. `find eggs`, iterates through all the task in Duke and if any of the tasks contains the description, -output: - Here are the matching tasks in your list: - 1.[T][✘] stock up on eggs - 2.[D][✘] buy eggs(by: Monday) - 3.[T][✘] create a new egg sandwich ### 3.13 Error Handling handles unexpected commands from the user such as unknown/incomplete command. if user enters an invalid command, the application will output a message that corresponds to what the user entered wrongly. @@ -173,35 +379,99 @@ things to include in version 2: ... +### 3.2 fridge commands + +To be able to execute the fridge commands the user must choose, type `'a'- remove all expired` or `'b' - add/remove/use an ingredient` in the main menu. + + while in mode `b`: + +by typing `template`, the user can see how to use which command + +by typing `show`, the user gets a list of all of the ingredients currently in the fridge, indexed and sorted by expiry date + +by typing `back`, he returns to the main menu + +#### 3.2.1 add an ingredient to the Fridge + +To add an ingredient to the Fridge, user needs to execute command below: + +Format: `add ` + +Examples: + +- `add chicken 250 3/11/2019` + +- `add cheese 150 11/11/2019` + + If the user adds an expired ingredient,eg. `add cheese 150 2/3/2019` he is warned by ` WARNING! expired ingredient: cheese, amount is: 100 expired on 2nd of March 2019` + +#### 3.2.2 remove an ingredient from the fridge + +To remove an ingredient from the Fridge, user needs to execute command below: + +Format: `remove ` + +The ingredient index can be found by typing `show`, see details above. + +Examples: + +- `remove 2` + + if user enters an invalid index, a similar error message will appear + + ` ☹ OOPS!!! Enter a valid ingredient number after delete, between 1 and 5. + You can type: + 'template' to see the format of the commands, + 'back' to see all your options, + 'q' to exit` + + + +#### 3.2.3 use an ingredient from the fridge + +To use an ingredient from the Fridge, user needs to execute command below: + +Format: `use ` + +Examples: + +- `use cheese 100` + + The user must use the most recently expiring ingredients in order to prevent food waste. + +### 3.3 remove all expired ingredients from the fridge + +From the main menu the user selects `a`, and it will remove all expired ingredients from the fridge. + +If there are no expired ingredients, he gets the following message: + +`☹ OOPS!!! Seems like you don't have any expired ingredients in the fridge!.` + +When the user loads the program if there are any expired ingredients in the fridge, he is notified by: + +`A gentle reminder you have some expired ingredients in the fridge` + `Would you like to see the list?` + +by typing `yes`, the list of expired ingredients is printed + +by typing anything else, the main menu appears where the user can select how he whishes to proceed. + + ## 4. Command Summary -Index | Keyword | Usage +Index | Keyword | Usage ----- | -------- | ---------- -1 | bye | bye -2 | list | list -3 | done | done -4 | todo | todo -5 | deadline | deadline /by -6 | event | event /at -7 | delete | delete -8 | find | find -9 | remind | remind -10 | stats | stats -11 | order | order -12 | preorder | preorder -13 | cancel | cancel -14 | help | help -15 | dishadd | dishadd /num -16 | dishdelete | dishdelete -17 | dishlist | dishlist -18 | addingredient | addingredient /add +1 | back | back +2 | template | template + | | + | | +15 | add | dishadd +16 | remove | remove +17 | list | list +18 | ingredient | ingredient # 5. FAQ Q: how do I transfer data to another computer A: install the application on the other computer and an empty recipe.txt will be created under the data folder. Replace this file with the same file found in your previous computer. therefore your data will be transferred - -Q: - -A: \ No newline at end of file diff --git a/docs/images/GenericListUML.png b/docs/images/GenericListUML.png new file mode 100644 index 00000000..6fe74e3b Binary files /dev/null and b/docs/images/GenericListUML.png differ diff --git a/docs/images/GenericListUML1.png b/docs/images/GenericListUML1.png new file mode 100644 index 00000000..a4b9a1e9 Binary files /dev/null and b/docs/images/GenericListUML1.png differ diff --git a/docs/images/StorageUML.png b/docs/images/StorageUML.png new file mode 100644 index 00000000..0bf7ee59 Binary files /dev/null and b/docs/images/StorageUML.png differ diff --git a/docs/images/StorageUML1.png b/docs/images/StorageUML1.png new file mode 100644 index 00000000..c9348af8 Binary files /dev/null and b/docs/images/StorageUML1.png differ diff --git a/docs/images/archh.png b/docs/images/archh.png new file mode 100644 index 00000000..47888713 Binary files /dev/null and b/docs/images/archh.png differ diff --git a/docs/images/architecture.png b/docs/images/architecture.png deleted file mode 100644 index 3930b4c0..00000000 Binary files a/docs/images/architecture.png and /dev/null differ diff --git a/docs/images/architectureV1.1.png b/docs/images/architectureV1.1.png deleted file mode 100644 index eab7aa5d..00000000 Binary files a/docs/images/architectureV1.1.png and /dev/null differ diff --git a/docs/images/dishes diagram.png b/docs/images/dishes diagram.png deleted file mode 100644 index 9c1556ac..00000000 Binary files a/docs/images/dishes diagram.png and /dev/null differ diff --git a/docs/images/dishes.PNG b/docs/images/dishes.PNG new file mode 100644 index 00000000..57a59279 Binary files /dev/null and b/docs/images/dishes.PNG differ diff --git a/docs/images/dishesCommand diagram.png b/docs/images/dishesCommand diagram.png deleted file mode 100644 index 62bcefcd..00000000 Binary files a/docs/images/dishesCommand diagram.png and /dev/null differ diff --git a/docs/images/dishesCommand.PNG b/docs/images/dishesCommand.PNG new file mode 100644 index 00000000..d6fa4039 Binary files /dev/null and b/docs/images/dishesCommand.PNG differ diff --git a/docs/images/fridgeUML.png b/docs/images/fridgeUML.png new file mode 100644 index 00000000..7a03872b Binary files /dev/null and b/docs/images/fridgeUML.png differ diff --git a/docs/images/fridgeUML1.png b/docs/images/fridgeUML1.png new file mode 100644 index 00000000..22082e2d Binary files /dev/null and b/docs/images/fridgeUML1.png differ diff --git a/src/main/.idea/$PRODUCT_WORKSPACE_FILE$ b/src/main/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 00000000..79be3548 --- /dev/null +++ b/src/main/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 11 + + + + + + + + \ No newline at end of file diff --git a/src/main/.idea/misc.xml b/src/main/.idea/misc.xml new file mode 100644 index 00000000..1763e153 --- /dev/null +++ b/src/main/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/.idea/modules.xml b/src/main/.idea/modules.xml new file mode 100644 index 00000000..122a9054 --- /dev/null +++ b/src/main/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/.idea/uiDesigner.xml b/src/main/.idea/uiDesigner.xml new file mode 100644 index 00000000..e96534fb --- /dev/null +++ b/src/main/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/.idea/vcs.xml b/src/main/.idea/vcs.xml new file mode 100644 index 00000000..b2bdec2d --- /dev/null +++ b/src/main/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/.idea/workspace.xml b/src/main/.idea/workspace.xml new file mode 100644 index 00000000..609ebda2 --- /dev/null +++ b/src/main/.idea/workspace.xml @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1572685001468 + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/data/fridge.txt b/src/main/data/fridge.txt new file mode 100644 index 00000000..fbf476aa --- /dev/null +++ b/src/main/data/fridge.txt @@ -0,0 +1,10 @@ +milk|3|09/09/2019 +cheese|4|12/12/2019 +rice|50|12/12/2019 +potato|3|12/2/2020 +rice|500|2/3/2020 +rice|250|2/3/2020 +rice|500|12/12/2020 +cheese|100|30/10/2019 +rice|501|12/10/2019 +rice|503|12/10/2019 diff --git a/src/main/data/order.txt b/src/main/data/order.txt new file mode 100644 index 00000000..890072dc --- /dev/null +++ b/src/main/data/order.txt @@ -0,0 +1,4 @@ +0|02/11/2019|D|fish|1|D|chili crab|1|D|rice|2 +0|12/11/2019|D|beef noodle|1|D|pork dumplings|2 +0|12/09/2020|D|beef noodle|1|D|chili crab|1|D|rice|3 +0|02/11/2019|D|cereal shrimp|1|D|soup|4 \ No newline at end of file diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 572e08df..3cffecee 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,74 +1,64 @@ package duke; -import duke.command.Cmd; +import duke.command.Command; +import duke.command.ViewTodoListCommand; import duke.command.ingredientCommand.ExitCommand; import duke.command.ingredientCommand.RemoveAllExpired; -import duke.dish.Dish; import duke.dish.DishList; import duke.exception.DukeException; import duke.fridge.Fridge; -import duke.ingredient.Ingredient; -import duke.order.Order; import duke.order.OrderList; import duke.parser.Parser; import duke.storage.FridgeStorage; import duke.storage.OrderStorage; -import duke.storage.Storage; -import duke.task.TaskList; import duke.ui.Ui; -import java.io.IOException; - /** * MAIN CLASS DUKE, start from main function. */ public class Duke { - // private Storage taskStorage; private FridgeStorage fridgeStorage; - private Storage orderStorage; - private TaskList tasks; + private OrderStorage orderStorage; private Ui ui; private DishList dish; private OrderList order; private Fridge fridge; + private final String fridgeFilePath = "data/fridge.txt"; + private final String orderFilePath = "data/order.txt"; + public enum Type { INGREDIENT, DISH, ORDER } + /** * The constructor method for Duke. - * - * @param filePath used to specify the location of the file in the hard disc. */ - public Duke(String filePath) { - String fridgeFilePath = "data/fridge.txt"; - String orderFilePath = "data/order.txt"; + public Duke() { dish = new DishList(); order = new OrderList(); fridge = new Fridge(); ui = new Ui(); - //taskStorage = new TaskStorage(filePath); - fridgeStorage = new FridgeStorage(fridgeFilePath); - orderStorage = new OrderStorage(orderFilePath); try { - //tasks = new TaskList(taskStorage.load().getAllEntries()); + fridgeStorage = new FridgeStorage(fridgeFilePath); + orderStorage = new OrderStorage(orderFilePath); fridge = new Fridge(fridgeStorage); + order = new OrderList(orderStorage.getEntries().getAllEntries()); } catch (DukeException e) { ui.showLoadingError(); - // System.out.println(e); e.printStackTrace(); - tasks = new TaskList(); } } - /** * The execution core of the Duke class. */ public void run() { String fullCommand; + //ui.clearScreen(); ui.showWelcome(); + if (fridge.hasExpiredIngredients()) { ui.showHasExpiring(); fullCommand = ui.readCommand(); @@ -77,52 +67,56 @@ public void run() { ui.show(fridge.getExpiredIngredients().toString()); } } - //ui.showOptions(); + ui.showLine(); boolean isExit = false; - boolean back = false; + while (!isExit) { try { + ui.chefDrawing(); ui.showOptions(); ui.showLine(); fullCommand = ui.readCommand(); + //ui.clearScreen(); ui.showLine(); - back = false; switch (fullCommand) { case "options": { ui.showOptions(); break; } case "q": { - Cmd command = new ExitCommand(); - command.execute(null, ui, null); + Command command = new ExitCommand(); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); + isExit = command.isExit(); + break; + } + case "t": { + Command command = new ViewTodoListCommand(); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); isExit = command.isExit(); break; } case "a": { - Cmd command = new RemoveAllExpired(fridge); - command.execute(fridge.getAllIngredients(), ui, fridgeStorage); + Command command = new RemoveAllExpired(fridge); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); isExit = command.isExit(); break; } case "b": { // ui.showIngredientsInFridge(fridge.getAllIngredients()); ui.showIngredientTask(); - while (true) { try { fullCommand = ui.readCommand(); + //ui.clearScreen(); if (fullCommand.trim().equals("back")) { break; } if (fullCommand.trim().equals("q")) { - - Cmd command = new ExitCommand(); - command.execute(null, ui, null); + Command command = new ExitCommand(); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); isExit = command.isExit(); break; - - } if (fullCommand.trim().equals("show")) { ui.showIngredientsInFridge(fridge.getAllIngredients()); @@ -132,9 +126,8 @@ public void run() { ui.showIngredientTemplate(); continue; } - - Cmd command = Parser.parse(fullCommand, Type.INGREDIENT); - command.execute(fridge.getAllIngredients(), ui, fridgeStorage); + Command command = Parser.parse(fullCommand, Type.INGREDIENT); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); } catch (DukeException e) { System.out.println(e.getLocalizedMessage()); // e.printStackTrace(); @@ -143,26 +136,62 @@ public void run() { break; } case "c": { - ui.showIngredientTask(); - fullCommand = ui.readCommand(); - Cmd command = Parser.parse(fullCommand, Type.ORDER); - command.execute(order, ui, orderStorage); + System.out.println("\t Managing order now\n\t You can type 'template' to retrieve command format"); + ui.showLine(); + while (true) { + try { + fullCommand = ui.readCommand(); + //ui.clearScreen(); + if (fullCommand.trim().equals("back")) { break; } + if (fullCommand.trim().equals("q")) { + Command command = new ExitCommand(); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); + isExit = command.isExit(); + break; + } + if (fullCommand.trim().equals("template")) { + ui.showOrderTemplate(); + continue; + } + Command command = Parser.parse(fullCommand, Type.ORDER); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); + } catch (DukeException e) { + System.out.println(e.getLocalizedMessage()); + } + } break; } case "d": { - ui.showIngredientTask(); - fullCommand = ui.readCommand(); - Cmd command = Parser.parse(fullCommand, Type.DISH); - command.execute(dish, ui, orderStorage); + while(true) { + try { + ui.showDishTemplate(); + fullCommand = ui.readCommand(); + //ui.clearScreen(); + if(fullCommand.trim().equals("q")) { + Command command = new ExitCommand(); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); + isExit = command.isExit(); + break; + } + if(fullCommand.trim().equals("back")) { + break; + } + if(fullCommand.trim().equals("template")) { + //ui.clearScreen(); + continue; + } + Command command = Parser.parse(fullCommand, Type.DISH); + command.execute(null, dish, order, ui, fridgeStorage, orderStorage); + } catch (DukeException e) { + System.out.println(e.getLocalizedMessage()); + } + } break; } default: throw new DukeException("wrong input"); - - } - - } catch (DukeException | IOException e) { + } catch (DukeException e) { ui.showError(e.getMessage()); } finally { ui.showLine(); @@ -174,6 +203,6 @@ public void run() { * =============== MAIN FUNCTION ===============. */ public static void main(String[] args) { - new Duke("data/tasks.txt").run(); + new Duke().run(); } -} +} \ No newline at end of file diff --git a/src/main/java/duke/command/Cmd.java b/src/main/java/duke/command/Cmd.java deleted file mode 100644 index 7db9d528..00000000 --- a/src/main/java/duke/command/Cmd.java +++ /dev/null @@ -1,21 +0,0 @@ -package duke.command; - -import duke.command.ingredientCommand.ExitCommand; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.ui.Ui; - -import java.io.IOException; - -public abstract class Cmd { - public abstract void execute(GenericList tasklist, Ui ui, Storage storage) throws DukeException, IOException; - /** - * Returns the boolean indicating that it is( not) an {@link ExitCommand}. - * - * @return false by default - */ - public boolean isExit() { - return false; - } -} diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java new file mode 100644 index 00000000..e509891d --- /dev/null +++ b/src/main/java/duke/command/Command.java @@ -0,0 +1,20 @@ +package duke.command; + +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.ui.Ui; + +public abstract class Command { + + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + throw new DukeException(" NANI??? Looks like one of our developer used the abstract class Cmd!"); + } + + public boolean isExit() { + return false; + } +} diff --git a/src/main/java/duke/command/FindIngredientCommand.java b/src/main/java/duke/command/FindIngredientCommand.java deleted file mode 100644 index 076d451c..00000000 --- a/src/main/java/duke/command/FindIngredientCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package duke.command; - -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.ingredient.*; -import duke.task.TaskList; -import duke.ui.Ui; - -/** - * Represents a specific {@link Cmd} used to find a String occurring in the {@link TaskList}. - */ -public class FindIngredientCommand extends Cmd { - - private String toFind; - - public FindIngredientCommand(String toFind) { - this.toFind = toFind; - } - - - - @Override - public void execute(GenericList tasklist, Ui ui, Storage storage) throws DukeException { - - } -} \ No newline at end of file diff --git a/src/main/java/duke/command/ViewTodoListCommand.java b/src/main/java/duke/command/ViewTodoListCommand.java new file mode 100644 index 00000000..e6c4c319 --- /dev/null +++ b/src/main/java/duke/command/ViewTodoListCommand.java @@ -0,0 +1,21 @@ +package duke.command; + +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.list.GenericList; +import duke.order.Order; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.storage.Storage; +import duke.ui.Ui; + +public class ViewTodoListCommand extends Command { + + @Override + public void execute(IngredientsList il, DishList dl, OrderList orderList, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + String info = (orderList).todoListToString(); + System.out.println(info); + } +} diff --git a/src/main/java/duke/command/dishesCommand/AddDishCommand.java b/src/main/java/duke/command/dishesCommand/AddDishCommand.java index 602aefe6..f04ead1b 100644 --- a/src/main/java/duke/command/dishesCommand/AddDishCommand.java +++ b/src/main/java/duke/command/dishesCommand/AddDishCommand.java @@ -1,57 +1,51 @@ package duke.command.dishesCommand; -import duke.command.ingredientCommand.AddCommand; -import duke.dish.DishList; +import duke.command.Command; import duke.dish.Dish; -import duke.command.Cmd; +import duke.dish.DishList; import duke.exception.DukeException; -import duke.storage.Storage; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; -public class AddDishCommand extends AddCommand { +public class AddDishCommand extends Command { private Dish dish; - private int amount; - private int Nb; - - public AddDishCommand(Dish dish, int amount) { - super(dish); + //constructor + public AddDishCommand(Dish dish) { this.dish = dish; - this.amount = amount; } - public void execute(DishList dishList, Ui ui, Storage storage) throws DukeException { + @Override + public void execute(IngredientsList il, DishList dishList, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { boolean flag = true; try { - if(dishList.size() == 0) { + if(dishList.size() == 0) { //if the list is empty, immediately add dish in it dishList.addEntry(dish); - dishList.getEntry(0).setNumberOfOrders(amount); - ui.showAddedDishes(dish.getDishname(), amount); + ui.showAddedDishes(dish.getDishname()); + //storage.update(); } else { - for( int i = 0; i < dishList.size(); i++) { + for( int i = 0; i < dishList.size(); i++) { //check for duplicates in list if(dishList.getEntry(i).getDishname().equals(dish.getDishname())){ - Nb = i; flag = false; //dish already exist in list break; } } - if(flag) { + if(flag) { //if there are no duplicates dishList.addEntry(dish); // add dish into list found in dishes class - dishList.getEntry(dishList.size() - 1).setNumberOfOrders(amount); - ui.showAddedDishes(dish.getDishname(), dishList.getEntry(dishList.size() - 1).getTotalNumberOfOrders()); + ui.showAddedDishes(dish.getDishname()); + //storage.update(); } - else { - dishList.getEntry(Nb).setNumberOfOrders(amount); - System.out.println("\t your updated orders:\n\t " - + dish.getDishname() + "\t amount: " + - String.valueOf(dishList.getEntry(Nb).getTotalNumberOfOrders())); + else { //if there are duplicates + System.out.println("\t dish already exist in list"); } } } catch (Exception e) { throw new DukeException("unable to add dish"); } } - } \ No newline at end of file diff --git a/src/main/java/duke/command/dishesCommand/AddIngredient.java b/src/main/java/duke/command/dishesCommand/AddIngredient.java index 32cd33b8..622c0dcf 100644 --- a/src/main/java/duke/command/dishesCommand/AddIngredient.java +++ b/src/main/java/duke/command/dishesCommand/AddIngredient.java @@ -1,32 +1,35 @@ package duke.command.dishesCommand; -import duke.command.ingredientCommand.AddCommand; +import duke.command.Command; import duke.dish.DishList; -import duke.command.Cmd; import duke.exception.DukeException; import duke.ingredient.Ingredient; import duke.ingredient.IngredientsList; -import duke.storage.Storage; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; -public class AddIngredient extends AddCommand { +//Adds an ingredient to the dish +public class AddIngredient extends Command { private Ingredient ingredient; + private int index; - - public AddIngredient(Ingredient ingredient) { - super(ingredient); + //constructor + public AddIngredient(Ingredient ingredient, int index) { + super(); this.ingredient = ingredient; - + this.index = index; } - - public void execute(DishList dishList, Ui ui, Storage storage) throws DukeException { + @Override + public void execute(IngredientsList il, DishList dishList, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { try { - // dishList.getEntry(Nb - 1).addIngredients(ingredient); - //System.out.println("\t added ingredient: " + ingredient + "\n\t to dish: " + dishList.getEntry(Nb - 1).getDishname()); + dishList.getEntry(index - 1).addIngredients(ingredient); + ui.showIngredients(ingredient,dishList.getEntry(index - 1)); } catch (Exception e) { - throw new DukeException("cannot add ingredient"); + throw new DukeException("cannot add ingredient as the dish is not in list"); } } -} \ No newline at end of file +} diff --git a/src/main/java/duke/command/dishesCommand/DeleteDishCommand.java b/src/main/java/duke/command/dishesCommand/DeleteDishCommand.java index 8bccffd7..49b1bd63 100644 --- a/src/main/java/duke/command/dishesCommand/DeleteDishCommand.java +++ b/src/main/java/duke/command/dishesCommand/DeleteDishCommand.java @@ -1,28 +1,30 @@ package duke.command.dishesCommand; -import duke.command.ingredientCommand.DeleteCommand; -import duke.dish.Dish; +import duke.command.Command; import duke.dish.DishList; -import duke.command.Cmd; import duke.exception.DukeException; -import duke.storage.Storage; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; -public class DeleteDishCommand extends DeleteCommand { +public class DeleteDishCommand extends Command { private int Nb; + //constructor public DeleteDishCommand(int dishNb) { - super(dishNb); this.Nb = dishNb; } - public void execute(DishList dish1, Ui ui, Storage storage) throws DukeException { + @Override + public void execute(IngredientsList il, DishList dishList, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { try { - ui.showDeletedDIsh(dish1.getEntry(Nb - 1).getDishname()); - dish1.removeEntry(Nb - 1); + ui.showDeletedDIsh(dishList.getEntry(Nb - 1).getDishname()); + dishList.removeEntry(Nb - 1); } catch (Exception e) { throw new DukeException("dish does not exist"); } } -} \ No newline at end of file +} diff --git a/src/main/java/duke/command/dishesCommand/InitCommand.java b/src/main/java/duke/command/dishesCommand/InitCommand.java deleted file mode 100644 index 14b12b13..00000000 --- a/src/main/java/duke/command/dishesCommand/InitCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -package duke.command.dishesCommand; - -import duke.dish.Dish; -import duke.dish.DishList; -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.ui.Ui; - -public class InitCommand extends Cmd { - - public InitCommand() { - //clears all the amount in dishes - } - - @Override - public void execute(GenericList dish1, Ui ui, Storage storage) throws DukeException { - System.out.println("\t are you sure you want to clear list? (yes or no)"); - String command = ui.readCommand(); - if(command.equals("yes")){ - dish1.clearList(); - System.out.println("\t LIST IS CLEARED"); - } - else if(command.equals("no")){ - System.out.println("\t LIST IS NOT CLEARED"); - } - } -} diff --git a/src/main/java/duke/command/dishesCommand/ListDishCommand.java b/src/main/java/duke/command/dishesCommand/ListDishCommand.java index e4ed135c..4cdacb98 100644 --- a/src/main/java/duke/command/dishesCommand/ListDishCommand.java +++ b/src/main/java/duke/command/dishesCommand/ListDishCommand.java @@ -1,27 +1,29 @@ package duke.command.dishesCommand; -import duke.command.ingredientCommand.ListCommand; -import duke.dish.Dish; +import duke.command.Command; import duke.dish.DishList; -import duke.command.Cmd; import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; - -public class ListDishCommand extends ListCommand { +public class ListDishCommand extends Command { @Override - public void execute(GenericList dish1, Ui ui, Storage storage) throws DukeException { - if (dish1.size() == 0) { + public void execute(IngredientsList il, DishList dishList, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + Object[][] data = new Object[dishList.size()][2]; //using text utils to display data in form of a table + if (dishList.size() == 0) { //if list is empty throw new DukeException("No Dishes yet!"); } else { System.out.println("\t Here are the dishes in your list:"); - for (int i = 1; i <= dish1.size(); i++) { // looping to print all the saved tasks - ui.showDishes("\t " + i + "." + dish1.getEntry(i - 1).getDishname() - , dish1.getEntry(i - 1).getTotalNumberOfOrders()); + for( int a = 0; a < dishList.size(); a++) { //store each dish along with its ingredients into data + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(dishList.getEntry(a).toString()); + data[a][0] = dishList.getEntry(a).getDishname(); + data[a][1] = stringBuilder; } } } -} \ No newline at end of file +} diff --git a/src/main/java/duke/command/dishesCommand/ResetDishCommand.java b/src/main/java/duke/command/dishesCommand/ResetDishCommand.java new file mode 100644 index 00000000..4da71ee4 --- /dev/null +++ b/src/main/java/duke/command/dishesCommand/ResetDishCommand.java @@ -0,0 +1,30 @@ +package duke.command.dishesCommand; + +import duke.command.Command; +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.ui.Ui; + +public class ResetDishCommand extends Command { + + @Override + public void execute(IngredientsList il, DishList dishList, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + System.out.println("\t are you sure you want to clear list? [y/n]"); + String command = ui.readCommand(); + if(command.toLowerCase().equals("y")){ + dishList.clearList(); + System.out.println("\t LIST IS CLEARED"); + } + else if(command.toLowerCase().equals("n")){ + System.out.println("\t LIST IS NOT CLEARED"); + } + else { + System.out.println("\t LIST IS NOT CLEARED"); + throw new DukeException("Please enter y or n after 'initialize' command"); + } + } +} diff --git a/src/main/java/duke/command/ingredientCommand/AddCommand.java b/src/main/java/duke/command/ingredientCommand/AddCommand.java index 13ba9f00..6dd0e980 100644 --- a/src/main/java/duke/command/ingredientCommand/AddCommand.java +++ b/src/main/java/duke/command/ingredientCommand/AddCommand.java @@ -1,47 +1,27 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; +import duke.command.Command; +import duke.dish.DishList; import duke.exception.DukeException; import duke.ingredient.Ingredient; import duke.ingredient.IngredientsList; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.Task; -import duke.task.TaskList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; -/** - * Represents a Command to add a specific {@link Task} in the {@link TaskList}. - */ -public class AddCommand extends Cmd { +public class AddCommand extends Command { - private T entry; + private Ingredient ingredient; - /** - * The constructor method for AddCommand. - * - * @param entry : the {@link Ingredient} to be added in the list - */ - public AddCommand(T entry) { - this.entry = entry; + public AddCommand(Ingredient i) { + ingredient = i; } - /** - * Public method used to add the task in the taskList, and write it on the hard disc. - * - * @param list the {@link IngredientsList} to be expanded - * @param ui {@link Ui} used for printing the task output - * @param storage {@link Storage} writes in the file on the hard disc - * @throws DukeException Error while adding the command to the duke.txt file - */ @Override - public void execute(GenericList list, Ui ui, Storage storage) throws DukeException { - list.addEntry(entry); - ui.showAddCommand(list.getEntry(entry).toString(), list.size()); - - storage.update(); - + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + il.addEntry(ingredient); + ui.showAddCommand(il.getEntry(ingredient).toString(), il.size()); + fs.update(); } - - -} +} \ No newline at end of file diff --git a/src/main/java/duke/command/ingredientCommand/DeleteCommand.java b/src/main/java/duke/command/ingredientCommand/DeleteCommand.java index ce4ab858..23d168b6 100644 --- a/src/main/java/duke/command/ingredientCommand/DeleteCommand.java +++ b/src/main/java/duke/command/ingredientCommand/DeleteCommand.java @@ -1,19 +1,19 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; +import duke.command.Command; +import duke.dish.DishList; import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.Task; -import duke.task.TaskList; +import duke.ingredient.Ingredient; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; import java.io.IOException; -/** - * Represents a specific {@link Cmd} used to delete a {@link Task} from the {@link TaskList}. - */ -public class DeleteCommand extends Cmd { +public class DeleteCommand extends Command { + private int taskNb; public DeleteCommand(int taskNb) { @@ -21,18 +21,17 @@ public DeleteCommand(int taskNb) { } @Override - public void execute(GenericList taskList, Ui ui, Storage storage) throws DukeException { - if (taskNb <= taskList.size() && taskNb > 0) { - T removed = taskList.removeEntry(taskNb - 1); - + public void execute(IngredientsList ingredientsList, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + if (taskNb <= ingredientsList.size() && taskNb > 0) { + Ingredient removed = ingredientsList.removeEntry(taskNb - 1); try { - storage.removeFromFile(taskNb - 1); + fs.removeFromFile(taskNb - 1); } catch (IOException e) { - throw new DukeException("Error while deleting the task from the hard disc"); + throw new DukeException("Error while deleting the ingredient from the hard disc"); } - ui.showRemovedTask(removed.toString(), taskList.size()); + ui.showRemovedIngredient(removed.toString(), ingredientsList.size()); } else { - throw new DukeException("Enter a valid task number after delete, between 1 and " + taskList.size()); + throw new DukeException("Enter a valid ingredient index number after delete, between 1 and " + ingredientsList.size()); } } } diff --git a/src/main/java/duke/command/ingredientCommand/DoneCommand.java b/src/main/java/duke/command/ingredientCommand/DoneCommand.java deleted file mode 100644 index a0b32555..00000000 --- a/src/main/java/duke/command/ingredientCommand/DoneCommand.java +++ /dev/null @@ -1,31 +0,0 @@ -package duke.command.ingredientCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.Task; -import duke.task.TaskList; -import duke.ui.Ui; - -/** - * Represents a specific {@link Cmd} used to mark a {@link Task} as done. - */ -public class DoneCommand extends Cmd { - private int taskNb; - - public DoneCommand(int taskNb) { - this.taskNb = taskNb; - } - - @Override - public void execute(GenericList taskList, Ui ui, Storage storage) throws DukeException { - if (taskNb < taskList.size() && taskNb >= 0) { - ((TaskList)taskList).markTaskDone(taskNb); - ui.showMarkDone(taskList.getEntry(taskNb).toString()); - storage.changeContent(taskNb); - } else { - throw new DukeException("Enter a valid task number after done, between 1 and " + taskList.size()); - } - } -} diff --git a/src/main/java/duke/command/ingredientCommand/ExitCommand.java b/src/main/java/duke/command/ingredientCommand/ExitCommand.java index 0fe6e595..04ece5b1 100644 --- a/src/main/java/duke/command/ingredientCommand/ExitCommand.java +++ b/src/main/java/duke/command/ingredientCommand/ExitCommand.java @@ -1,15 +1,15 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.TaskList; +import duke.command.Command; +import duke.dish.DishList; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; -/** - * Represents a specific {@link Cmd} used to exit the program after the user inputs "bye". - */ -public class ExitCommand extends Cmd{ +//Exits the program +public class ExitCommand extends Command { @Override public boolean isExit() { @@ -17,7 +17,7 @@ public boolean isExit() { } @Override - public void execute(GenericList taskList, Ui ui, Storage storage) { + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) { System.out.println("\t Bye. Hope to see you again soon!"); } } diff --git a/src/main/java/duke/command/ingredientCommand/FindIngredientCommand.java b/src/main/java/duke/command/ingredientCommand/FindIngredientCommand.java index 7941e413..6b2100ef 100644 --- a/src/main/java/duke/command/ingredientCommand/FindIngredientCommand.java +++ b/src/main/java/duke/command/ingredientCommand/FindIngredientCommand.java @@ -1,27 +1,48 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; +import duke.command.Command; +import duke.dish.DishList; import duke.exception.DukeException; import duke.ingredient.Ingredient; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.TaskList; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; +import java.text.SimpleDateFormat; + /** - * Represents a specific {@link Cmd} used to find a String occurring in the {@link TaskList}. + * Represents a specific {@link Command} used to find a String occurring in the {@link Ingredient}. */ -public class FindIngredientCommand extends Cmd { +public class FindIngredientCommand extends Command { private String toFind; + private SimpleDateFormat simpleDateFormat; public FindIngredientCommand(String toFind) { this.toFind = toFind; + simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); } - @Override - public void execute(GenericList ingList, Ui ui, Storage storage) throws DukeException { + public void execute(IngredientsList ingList, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + int i = 1; + StringBuilder sb = new StringBuilder(); + for (Ingredient ingredient : ingList.getAllEntries()) { //for every ingredient, scan through the ingredientslist + i += 1; + if (ingredient.getName().equals(toFind)) + { + sb.append("\t ").append(i-1).append(". ").append(ingredient.getName()).append(" ").append(ingredient.getAmount()).append(" ").append(simpleDateFormat.format(ingredient.getExpiryDate())).append("."); + sb.append(System.lineSeparator()); + } + } + if (sb.length() == 0) { + System.out.println("No such ingredient found!"); + } else { + System.out.println("\t These are the ingredients you searched for!"); + ui.showTask(sb.toString()); + } } } diff --git a/src/main/java/duke/command/ingredientCommand/FindToday.java b/src/main/java/duke/command/ingredientCommand/FindToday.java index 46876f58..d2bd0259 100644 --- a/src/main/java/duke/command/ingredientCommand/FindToday.java +++ b/src/main/java/duke/command/ingredientCommand/FindToday.java @@ -1,43 +1,44 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.Task; -import duke.task.TaskList; +import duke.command.Command; +import duke.dish.DishList; +import duke.ingredient.Ingredient; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; import java.text.SimpleDateFormat; -import java.util.Date; -public class FindToday extends Cmd { - private Date today = new Date(); - private String pattern = "dd/MM/yyyy"; - private SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); - private String TodayDate = simpleDateFormat.format(today); +public class FindToday extends Command { - @Override - public boolean isExit() { - return false; + private SimpleDateFormat simpleDateFormat; + + public FindToday(){ + simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); } - public void execute(GenericList taskList, Ui ui, Storage storage) { + @Override + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) { int i = 1; StringBuilder sb = new StringBuilder(); - - for (Task task : taskList.getAllEntries()) { - if (task.getDescription().contains(TodayDate)) { - sb.append("\t ").append(i++).append(".").append(task.toString()); + for (Ingredient ingredient : il.getAllEntries()) + { //for every ingredient, scan through the ingredient list + i += 1; + if (ingredient.isExpiredToday(simpleDateFormat.format(ingredient.getExpiryDate()))) + { + sb.append("\t ").append(i-1).append(". ").append(il.getEntry(ingredient).toStringNoWarning()).append("."); sb.append(System.lineSeparator()); } } if (sb.length() == 0) { - System.out.println("No ingredients for today!"); + System.out.println("No expired ingredients for today!"); } else { - System.out.println("\t Here are the ingredients for today"); + System.out.println("\t Here are the expired ingredients for today"); + ui.showTask(sb.toString()); } - sb.setLength(sb.length() - 1);// to remove the last new line - System.out.println(sb.toString()); + } } diff --git a/src/main/java/duke/command/ingredientCommand/ListCommand.java b/src/main/java/duke/command/ingredientCommand/ListCommand.java index 86d1dc9f..17267cbe 100644 --- a/src/main/java/duke/command/ingredientCommand/ListCommand.java +++ b/src/main/java/duke/command/ingredientCommand/ListCommand.java @@ -1,26 +1,27 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; +import duke.command.Command; +import duke.dish.DishList; import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.Task; -import duke.task.TaskList; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; /** - * Represents a specific {@link Cmd} used to list all the {@link Task}s in the {@link TaskList}. + * Represents a specific {@link Command} used to list all the Ingredients in the {@link IngredientsList}. */ -public class ListCommand extends Cmd { +public class ListCommand extends Command { @Override - public void execute(GenericList taskList, Ui ui, Storage storage) throws DukeException { - if (taskList.size() == 0) { - throw new DukeException("No tasks yet!"); + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + if (il.size() == 0) { + throw new DukeException("No ingredients yet!"); } else { - System.out.println("\t Here are the tasks in your list:"); - for (int i = 1; i <= taskList.size(); i++) { // looping to print all the saved tasks - ui.showTask("\t " + i + "." + taskList.getEntry(i - 1).toString()); + System.out.println("\t Here are the ingredients in your list:"); + for (int i = 1; i <= il.size(); i++) { // looping to print all the saved tasks + ui.showTask("\t " + i + "." + il.getEntry(i - 1).toString()); } } } diff --git a/src/main/java/duke/command/ingredientCommand/RemindCommand.java b/src/main/java/duke/command/ingredientCommand/RemindCommand.java deleted file mode 100644 index edf1f705..00000000 --- a/src/main/java/duke/command/ingredientCommand/RemindCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -package duke.command.ingredientCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.Task; -import duke.task.TaskList; -import duke.ui.Ui; - -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.Date; - -/** - * One of the B-Extensions. - * @author 9hafidz6 - */ -public class RemindCommand extends Cmd { - - public RemindCommand() { - //An empty constructor method - } - - @Override - public void execute(GenericList taskList, Ui ui, Storage storage) throws DukeException { - int num = 1; - LocalDate date = LocalDate.now(); - LocalDate date1 = date.plusDays(5); - - Date startDate = Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()); - Date endDate = Date.from(date1.atStartOfDay(ZoneId.systemDefault()).toInstant()); - - if (taskList.size() == 0) { - System.out.println("You have no upcoming events/deadlines/todos"); - } else { - System.out.println("These are your Tasks in the next 5 days"); - for (int a = 0; a < taskList.size(); a++) { - Date taskDate = ((Task)taskList.getEntry(a)).getCurrentDate(); - - if ((isWithinRange(taskDate, endDate, startDate))) { - System.out.println(num + ": " + taskList.getEntry(a).toString()); - num++; - } - } - } - } - - private boolean isWithinRange(Date taskDate, Date endDate, Date startDate) { - return taskDate.before(endDate) && taskDate.after(startDate); - } -} diff --git a/src/main/java/duke/command/ingredientCommand/RemoveAllExpired.java b/src/main/java/duke/command/ingredientCommand/RemoveAllExpired.java index 16112eaf..797865e7 100644 --- a/src/main/java/duke/command/ingredientCommand/RemoveAllExpired.java +++ b/src/main/java/duke/command/ingredientCommand/RemoveAllExpired.java @@ -1,29 +1,28 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; +import duke.command.Command; +import duke.dish.DishList; import duke.exception.DukeException; import duke.fridge.Fridge; -import duke.ingredient.Ingredient; import duke.ingredient.IngredientsList; -import duke.list.GenericList; +import duke.order.OrderList; import duke.storage.FridgeStorage; -import duke.storage.Storage; +import duke.storage.OrderStorage; import duke.ui.Ui; -import java.io.IOException; - -public class RemoveAllExpired extends Cmd { +public class RemoveAllExpired extends Command { private Fridge fridge; + public RemoveAllExpired(Fridge fridge){ - this.fridge=fridge; + this.fridge = fridge; } + @Override - public void execute(GenericList tasklist, Ui ui, Storage storage) throws DukeException, IOException { + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { if(fridge.hasExpiredIngredients()) { - //System.out.println(" has expired "+fridge.getExpiredIngredients().size()); IngredientsList expired=fridge.removeExpired(); - (storage).update(); + (fs).update(); ui.show(" Removed: "+expired.toString()); } else diff --git a/src/main/java/duke/command/ingredientCommand/Snooze.java b/src/main/java/duke/command/ingredientCommand/Snooze.java deleted file mode 100644 index 89c285c7..00000000 --- a/src/main/java/duke/command/ingredientCommand/Snooze.java +++ /dev/null @@ -1,50 +0,0 @@ -package duke.command.ingredientCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.parser.Convert; -import duke.storage.Storage; -import duke.task.Task; -import duke.task.TaskList; -import duke.ui.Ui; - -import java.util.Date; - -/** - * One of the B-Extensions. - * @author saradj - */ -public class Snooze extends Cmd { - - private int taskNb; - private String until; - private Date date; - - /** - * The constructor method for snooze. - * - * @param taskNb task number - * @param until snooze until when - */ - public Snooze(int taskNb, String until) { - this.taskNb = taskNb; - this.until = until; - this.date = Convert.stringToDate(until); - } - - @Override - public void execute(GenericList taskList, Ui ui, Storage storage) throws DukeException { - if (taskNb < taskList.size() && taskNb >= 0) { - if (taskList.getEntry(taskNb).isDone()) { - throw new DukeException("Seems like you've already finished that task, no need to snooze it now"); - } - ((TaskList)taskList).changeTaskDate(taskNb, until); - ui.showChangedDate(Convert.getDateString(date, until),taskList.getEntry(taskNb).toString()); - storage.changeContent(taskNb); - } else { - throw new DukeException("Enter a valid task number after snooze, between 1 and " + taskList.size()); - } - } -} - diff --git a/src/main/java/duke/command/ingredientCommand/UseCommand.java b/src/main/java/duke/command/ingredientCommand/UseCommand.java index 405fbfc9..183ed890 100644 --- a/src/main/java/duke/command/ingredientCommand/UseCommand.java +++ b/src/main/java/duke/command/ingredientCommand/UseCommand.java @@ -1,27 +1,29 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; +import duke.command.Command; +import duke.dish.DishList; import duke.exception.DukeException; import duke.ingredient.Ingredient; -import duke.list.GenericList; -import duke.storage.Storage; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.ui.Ui; -import java.io.IOException; - -public class UseCommand extends Cmd { +public class UseCommand extends Command { private Ingredient toUse; public UseCommand(Ingredient ingredient){ - toUse=ingredient; + toUse = ingredient; } @Override - public void execute(GenericList ingredientList, Ui ui, Storage storage) throws DukeException, IOException { - if(ingredientList.removeEntry(toUse)){ - ui.show("Great you used "+ toUse.toStringWithoutDate()); - storage.update(); - }else - ui.show("There is not a sufficient amount of "+toUse.getName()+" that is not expired, maybe you could buy some first? "); + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + if (il.removeEntry(toUse)) { + ui.show("Great you used "+ toUse.toStringWithoutDate()); + fs.update(); + } else { + ui.show("There is not a sufficient amount of " + toUse.getName() + " that is not expired, maybe you could buy some first? "); + } } } diff --git a/src/main/java/duke/command/ingredientCommand/ViewCommand.java b/src/main/java/duke/command/ingredientCommand/ViewCommand.java index 0614dcf8..1a7efc98 100644 --- a/src/main/java/duke/command/ingredientCommand/ViewCommand.java +++ b/src/main/java/duke/command/ingredientCommand/ViewCommand.java @@ -1,20 +1,23 @@ package duke.command.ingredientCommand; -import duke.command.Cmd; -import duke.list.GenericList; -import duke.storage.Storage; -import duke.task.Task; +import duke.command.Command; +import duke.dish.DishList; +import duke.ingredient.Ingredient; +import duke.ingredient.IngredientsList; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; import duke.task.TaskList; import duke.ui.Ui; import java.util.Date; /** - * Represents a specific {@link Cmd} used to find a String occurring in the {@link TaskList}. + * Represents a specific {@link Command} used to find a String occurring in the {@link TaskList}. * One of the B-Extensions. * @author x3chillax */ -public class ViewCommand extends Cmd { +public class ViewCommand extends Command { private Date toView; @@ -23,14 +26,14 @@ public ViewCommand(Date toView) { } @Override - public void execute(GenericList taskList, Ui ui, Storage storage) { + public void execute(IngredientsList il, DishList dl, OrderList ol, Ui ui, FridgeStorage fs, OrderStorage os) { StringBuilder sb = new StringBuilder(); int i = 1; try { - for (Task task : taskList.getAllEntries()) { - if ((task.getCurrentDate()).equals(toView)) { + for (Ingredient ingredient : il.getAllEntries()) { + if ((ingredient.getExpiryDate()).equals(toView)) { //TODO: needs work on this part. comparing of time use Date always takes into account time 0000 - sb.append("\t ").append(i++).append(".").append(task.toString()); + sb.append("\t ").append(i++).append(".").append(ingredient.toString()); sb.append(System.lineSeparator()); } } diff --git a/src/main/java/duke/command/orderCommand/AddOrder.java b/src/main/java/duke/command/orderCommand/AddOrder.java deleted file mode 100644 index 32104c1a..00000000 --- a/src/main/java/duke/command/orderCommand/AddOrder.java +++ /dev/null @@ -1,194 +0,0 @@ -package duke.command.orderCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.order.Order; -import duke.order.OrderList; -import duke.storage.Storage; -import duke.ui.Ui; - -import java.io.IOException; - -public class AddOrder extends Cmd { - - private Order order; - - /** - * The constructor method (1) for AddCommand. - */ - public AddOrder() { - this.order = new Order(); - } - - /** - * The constructor method (2) for AddCommand. - * - * @param order : the {@link Order} to be added in the list - */ - public AddOrder(Order order) { - this.order = order; - } - - /** - * Public method used to add a new order in the orderList, and write it on the hard disc. - * - * @param orderList the {@link OrderList} to be expanded - * @param ui {@link Ui} used for printing the order output - * @param storage {@link Storage} writes in the file on the hard disc - * @throws DukeException Error while adding the command to the duke.txt file - */ - @Override - public void execute(GenericList orderList, Ui ui, Storage storage) throws DukeException { - - printStartMsg(ui); - String orderDate = getOrderDate(ui); - printMenu(); - - order = new Order(); - String[] orders = new String[0]; - boolean isConfirmed = false; - while (!isConfirmed) { - try { - String fullCommand = ui.readCommand(); - ui.showLine(); - String[] split = fullCommand.split(", "); - System.out.println("You have ordered:"); - showOrderContent(split); - System.out.println("Confirm [Y/N]?"); - isConfirmed = (ui.readCommand().toLowerCase()=="y")? true: false; - orders = split; - } catch (DukeException e) { - ui.showError(e.getMessage()); - } - } - - String customerName = ""; - if (orderDate!="") { customerName = getCustomerName(ui); } - - printConfirmMsg(order, orderDate, customerName); - - //Add dishes into order - for (String s : orders) { - String[] Dish = s.split("\\*", 2); - //order.addDish(Integer.parseInt(Dish[0]), Integer.parseInt(Dish[1])); - } - - orderList.addEntry(order); - ui.showAddOrder(order.toString(), orderList.size()); - try { - storage.addInFile(order.printInFile()); - - //To do - //how to read from order.txt - //separate storage from task storage class - - } catch (IOException e) { - throw new DukeException("Error while adding the command to the orders.txt file"); - } - } //category - - - public void printStartMsg(Ui ui) { - System.out.println("Hello! Welcome to restaurant SUPERDELIOUS!"); - } - - public void printMenu() { - System.out.println("Start ordering..."); - System.out.println("Here is the menu. What would you like to order?"); - System.out.println("=============================================="); - System.out.println(" Today's Menu "); - System.out.println("[1] Beef Noodle $5.50\n" + - "[2] Pork Dumplings $4.50\n" + - "[3] Chili Crab $8.00\n" + - "[4] Cereal Prawn $6.50\n" + - "[5] Laksa $4.50\n" + - "[6] Chicken Rice $4.00\n" + - "[7] Seasonal Vegetables $3.00"); - - //To do - //Print out menu info by iteration rather than manually printing out - //rewritten this part after menu/dish part is done - - System.out.println("=============================================="); - } - - public void printConfirmMsg(Order order, String preOrderDate, String customerName) throws DukeException { - if (preOrderDate=="") { - System.out.println("Order received. Start preparing now..."); - } else { - order.setDate(preOrderDate); - System.out.println("Order received. Please come at "+preOrderDate+" on time."); } - } - - public String getOrderDate(Ui ui) { - System.out.println("Reservation or not [Y/N]?"); - boolean isPreOrder = (ui.readCommand().toLowerCase() == "y")? true:false; - if (isPreOrder) { - System.out.println("Please specify the serving date:"); - String date = ui.readCommand(); - return date; - } else {return "";} - - } - - public String getCustomerName(Ui ui) { - System.out.println("What name is the reservation under, sir/madam?"); - String name = ui.readCommand(); - return name; - } - - public String getDishName(String dishNb) throws DukeException { - try { - switch (dishNb) { - case "[1]": return "Beef Noodle"; - case "[2]": return "Pork Dumplings"; - case "[3]": return "Chili Crab"; - case "[4]": return "Cereal Prawn"; - case "[5]": return "Laksa"; - case "[6]": return "Chicken Rice"; - case "[7]": return "Seasonal Vegetables"; - default: - throw new DukeException("No corresponding dishes in today's menu!"); - } - }catch (Exception e){ - e.getMessage(); - } - return ""; - } - - public double getDishPrice(String dishNb) throws DukeException { - try { - switch (dishNb) { - case "[1]": return 5.5; - case "[2]": return 4.5; - case "[3]": return 8.0; - case "[4]": return 6.5; - case "[5]": return 4.5; - case "[6]": return 4.0; - case "[7]": return 3.0; - default: - throw new DukeException("No corresponding dishes in today's menu!"); - } - }catch (Exception e){ - e.getMessage(); - } - return 0; - } - - public void showOrderContent(String[] commandList) throws DukeException { - //commandList contains the dishes number and dishes amount - int total = 0; - int cnt = 0; - for (String s: commandList) { - String[] Dish = s.split("\\*", 2); - String DishName = getDishName(Dish[0]); - String DishAmount = Dish[1]; - cnt += Integer.parseInt(DishAmount); - total += Integer.parseInt(DishAmount) * getDishPrice(Dish[0]); - System.out.println(DishAmount+" "+DishName); - } - System.out.println("Total: "+cnt+" dishes, $"+total); - } - -} diff --git a/src/main/java/duke/command/orderCommand/AddOrderCommand.java b/src/main/java/duke/command/orderCommand/AddOrderCommand.java new file mode 100644 index 00000000..2354b846 --- /dev/null +++ b/src/main/java/duke/command/orderCommand/AddOrderCommand.java @@ -0,0 +1,45 @@ +package duke.command.orderCommand; + +import duke.command.Command; +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.order.Order; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.storage.Storage; +import duke.ui.Ui; + +import java.io.IOException; + +public class AddOrderCommand extends Command { + + private Order order; + + /** + * The constructor method for AddOrderCommand. + * + * @param order : the {@link Order} to be added in the list + */ + public AddOrderCommand(Order order) { + this.order = order; + } + + /** + * Public method used to add a new order in the orderList, and write it on the hard disc. + * + * @param orderList the {@link OrderList} to be expanded + * @param ui {@link Ui} used for printing the order output + * @param os {@link Storage} writes in the file on the hard disc + * @throws DukeException Error while adding the command to the duke.txt file + */ + @Override + public void execute(IngredientsList il, DishList dl, OrderList orderList, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + orderList.addEntry(order); + ui.showLine(); + ui.showAddOrder(order.toString(), orderList.size()); + + // TODO: store the new order into file + } +} diff --git a/src/main/java/duke/command/orderCommand/AlterDateCommand.java b/src/main/java/duke/command/orderCommand/AlterDateCommand.java new file mode 100644 index 00000000..530ce931 --- /dev/null +++ b/src/main/java/duke/command/orderCommand/AlterDateCommand.java @@ -0,0 +1,51 @@ +package duke.command.orderCommand; + +import duke.command.Command; +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.order.Order; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.ui.Ui; + +import java.util.Date; + +/** + * Represents a specific {@link Command} used to alter the {@link Order} serving date. + */ +public class AlterDateCommand extends Command { + + private int orderIndex; + private Date date; + + /** + * The constructor method for {@link AlterDateCommand}. + * + * @param orderNumber order index number, starting from 1, maximum orderList.size() + * @param newDate new serving date of the {@link Order} + */ + public AlterDateCommand(int orderNumber, Date newDate) { + this.orderIndex = orderNumber; + this.date = newDate; + } + + @Override + public void execute(IngredientsList il, DishList dl, OrderList orderList, Ui ui, FridgeStorage fs, OrderStorage orderStorage) throws DukeException { + if (orderList.size()==0) { + throw new DukeException("No order in the list! No order can be altered!"); + } + if (orderIndex < orderList.size() && orderIndex >= 0) { + Order order = orderList.getEntry(orderIndex); + if (order.isDone()) { throw new DukeException("Order done already. Date alteration is not expected."); } + order.setDate(date); + ui.showOrderChangedDate(order.getDate(),orderList.getEntry(orderIndex).toString()); + orderStorage.changeContent(orderIndex+1); + // TODO: update today's dish(task) list if new date is today + } else { + throw new DukeException("Must enter a valid order index number between 1 and "+orderList.size()); + } + } +} + diff --git a/src/main/java/duke/command/orderCommand/AlterServingDateCmd.java b/src/main/java/duke/command/orderCommand/AlterServingDateCmd.java deleted file mode 100644 index c619ab48..00000000 --- a/src/main/java/duke/command/orderCommand/AlterServingDateCmd.java +++ /dev/null @@ -1,45 +0,0 @@ -package duke.command.orderCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.order.Order; -import duke.order.OrderList; -import duke.storage.Storage; -import duke.ui.Ui; - -/** - * Represents a specific {@link Cmd} used to alter the {@link Order} serving date. - */ -public class AlterServingDateCmd extends Cmd { - - private int orderNb; - private String date; - - /** - * The constructor method for {@link AlterServingDateCmd}. - * - * @param number order number - * @param newDate new serving date of the {@link Order} - */ - public AlterServingDateCmd(int number, String newDate) { - this.orderNb = number; - this.date = newDate; - } - - @Override - public void execute(GenericList orderList, Ui ui, Storage storage) throws DukeException { - if (orderNb < orderList.size() && orderNb >= 0) { - if (orderList.getEntry(orderNb).isDone()) { - throw new DukeException("Order done already. No alteration is expected."); - } - ((OrderList)orderList).changeOrderDate(orderNb, date); - ui.showOrderChangedDate(date,orderList.getEntry(orderNb).toString()); - storage.changeContent(orderNb); - } else { - throw new DukeException("Please enter a valid order number between 1 and " - + orderList.size() + " to alter the serving date"); - } - } -} - diff --git a/src/main/java/duke/command/orderCommand/CancelOrderCmd.java b/src/main/java/duke/command/orderCommand/CancelOrderCmd.java deleted file mode 100644 index d9e6ec65..00000000 --- a/src/main/java/duke/command/orderCommand/CancelOrderCmd.java +++ /dev/null @@ -1,57 +0,0 @@ -package duke.command.orderCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.order.Order; -import duke.order.OrderList; -import duke.storage.Storage; -import duke.ui.Ui; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a specific {@link Cmd} used to cancel/delete a {@link Order} from the {@link OrderList}. - */ -public class CancelOrderCmd extends Cmd { - private int orderNb; - - /** - * the constructor method of class {@link CancelOrderCmd} - * - * @param number order number in the order list - * @throws DukeException if input cannot be converted into a number - */ - public CancelOrderCmd(String number) throws DukeException { - int index; - try { index = Integer.parseInt(number) - 1; } - catch (Exception e) { throw new DukeException(e.getMessage()); } - this.orderNb = index; - } - - @Override - public void execute(GenericList orderList, Ui ui, Storage storage) throws DukeException { - if (orderList.size()==0) { - throw new DukeException("No order in the list! No order can be cancelled!"); - } - if (orderNb < orderList.size() && orderNb >= 0) { - Order removed = orderList.removeEntry(orderNb); - List fileContent = null; - try { - fileContent = new ArrayList<>(Files.readAllLines(storage.getPath(), StandardCharsets.UTF_8)); - fileContent.remove(orderNb); // changing the file content - Files.write(storage.getPath(), fileContent, StandardCharsets.UTF_8); - } catch (IOException e) { - throw new DukeException("Error while cancelling the order from the hard disc."); - } - ui.showRemovedOrder(removed.toString(), orderList.size()); - } else { - throw new DukeException("Please enter a valid order number between 1 and " + orderList.size() + " to cancel."); - } - } - -} diff --git a/src/main/java/duke/command/orderCommand/DeleteOrderCommand.java b/src/main/java/duke/command/orderCommand/DeleteOrderCommand.java new file mode 100644 index 00000000..2724ce00 --- /dev/null +++ b/src/main/java/duke/command/orderCommand/DeleteOrderCommand.java @@ -0,0 +1,47 @@ +package duke.command.orderCommand; + +import duke.command.Command; +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.order.Order; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.ui.Ui; + +import java.io.IOException; + +/** + * Represents a specific {@link Command} used to cancel/delete a {@link Order} from the {@link OrderList}. + */ +public class DeleteOrderCommand extends Command { + private int orderIndex; + + /** + * the constructor method of class {@link DeleteOrderCommand} + * + * @param orderNumber order number in the order list + */ + public DeleteOrderCommand(int orderNumber) { + this.orderIndex = orderNumber; + } + + @Override + public void execute(IngredientsList il, DishList dl, OrderList orderList, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + if (orderList.size()==0) { throw new DukeException("No order in the list! No order can be removed!"); } + if (orderIndex < orderList.size() && orderIndex >= 0) { + Order removed = orderList.getEntry(orderIndex); + // TODO: update chef's to do list + ui.showRemovedOrder(removed.toString(), orderList.size()); + orderList.removeEntry(orderIndex); + try { + os.removeFromFile(orderIndex + 1); + } catch (IOException e) { + throw new DukeException(e.getMessage()); + } + } else { + throw new DukeException("Please enter a valid order number between 1 and " + orderList.size() + " to remove"); + } + } +} diff --git a/src/main/java/duke/command/orderCommand/DoneOrderCmd.java b/src/main/java/duke/command/orderCommand/DoneOrderCmd.java deleted file mode 100644 index cae5169b..00000000 --- a/src/main/java/duke/command/orderCommand/DoneOrderCmd.java +++ /dev/null @@ -1,43 +0,0 @@ -package duke.command.orderCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.order.Order; -import duke.order.OrderList; -import duke.storage.Storage; -import duke.ui.Ui; - -/** - * Represents a specific {@link Cmd} used to mark a {@link Order} as done. - */ -public class DoneOrderCmd extends Cmd { - private int orderNb; - - /** - * the constructor method of {@link DoneOrderCmd} - * - * @param number order number in the order list - * @throws DukeException if input cannot be converted into number - */ - public DoneOrderCmd(String number) throws DukeException{ - int index; - try { index = Integer.parseInt(number) - 1; } - catch (Exception e) { throw new DukeException("Please enter a valid order number."); } - this.orderNb = index; - } - - @Override - public void execute(GenericList orderList, Ui ui, Storage storage) throws DukeException { - if (orderList.size()==0) { - throw new DukeException("No order in the list! No order can be done!"); - } - if (orderNb < orderList.size() && orderNb >= 0) { - (( OrderList)orderList).markOrderDone(orderNb); - ui.showMarkDone(orderList.getEntry(orderNb).toString()); - storage.changeContent(orderNb); - } else { - throw new DukeException("Please enter a valid order number after done, between 1 and " + orderList.size()); - } - } -} diff --git a/src/main/java/duke/command/orderCommand/DoneOrderCommand.java b/src/main/java/duke/command/orderCommand/DoneOrderCommand.java new file mode 100644 index 00000000..6a2c69b3 --- /dev/null +++ b/src/main/java/duke/command/orderCommand/DoneOrderCommand.java @@ -0,0 +1,49 @@ +package duke.command.orderCommand; + +import duke.command.Command; +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.order.Order; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.ui.Ui; + +/** + * Represents a specific {@link Command} used to mark a {@link Order} as done. + */ +public class DoneOrderCommand extends Command { + private int orderIndex; + + /** + * the constructor method of {@link DoneOrderCommand} + * + * @param orderNumber order number in the order list + */ + public DoneOrderCommand(int orderNumber) { + this.orderIndex = orderNumber; + } + + @Override + public void execute(IngredientsList il, DishList dl, OrderList orderList, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + if (orderList.size()==0) { + throw new DukeException("No order in the list! No order can be done!"); + } + if (orderIndex < orderList.size() && orderIndex >= 0) { + Order doneOrder = orderList.getEntry(orderIndex); + if (doneOrder.isDone()) { + int number = orderIndex+1; + throw new DukeException("Order "+number+" has already been done!"); + } + os.changeContent(orderIndex+1); + + // TODO: update chef's to do list + + orderList.markOrderDone(orderIndex); + ui.showMarkDoneOrder(orderList.getEntry(orderIndex).toString()); + } else { + throw new DukeException("Must enter a valid order number, between 1 and " + orderList.size() + " to be done"); + } + } +} diff --git a/src/main/java/duke/command/orderCommand/FindOrderByDate.java b/src/main/java/duke/command/orderCommand/FindOrderByDate.java deleted file mode 100644 index d6cfc2a6..00000000 --- a/src/main/java/duke/command/orderCommand/FindOrderByDate.java +++ /dev/null @@ -1,46 +0,0 @@ -package duke.command.orderCommand; - -import duke.command.Cmd; -import duke.list.GenericList; -import duke.order.Order; -import duke.order.OrderList; -import duke.parser.Convert; -import duke.storage.Storage; -import duke.ui.Ui; - -import java.util.Date; - -public class FindOrderByDate extends Cmd { - - private Date toView; - - public FindOrderByDate(String command) { - //expected to be "date xxxx" - String date = command.split(" ")[1]; - Date toView = Convert.stringToDate(date); - this.toView = toView; - } - - @Override - public void execute(GenericList orderList, Ui ui, Storage storage) { - StringBuilder sb = new StringBuilder(); - int i = 1; - try { - for (Order order : orderList.getAllEntries()) { - if ((order.getDate()).equals(toView)) { - sb.append("\t ").append(i++).append(".").append(order.toString()); - sb.append(System.lineSeparator()); - } - } - if (sb.length() == 0) { - System.out.println("No matching date found! "); - } else { - System.out.println("\t Here are the orders on "+ toView); - } - sb.setLength(sb.length() - 1); // to remove the last new line - System.out.println(sb.toString()); - } catch (Exception e) { - System.out.println(e.getMessage()); - } - } -} diff --git a/src/main/java/duke/command/orderCommand/InitOrderListCommand.java b/src/main/java/duke/command/orderCommand/InitOrderListCommand.java new file mode 100644 index 00000000..8ab81cc8 --- /dev/null +++ b/src/main/java/duke/command/orderCommand/InitOrderListCommand.java @@ -0,0 +1,46 @@ +package duke.command.orderCommand; + +import duke.command.Command; +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.list.GenericList; +import duke.order.Order; +import duke.order.OrderList; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.storage.Storage; +import duke.ui.Ui; + +/** + * Represents a specific {@link Command} used to clear all the {@link Order}s in the order list. + * + */ +public class InitOrderListCommand extends Command { + + public InitOrderListCommand() { + } + + @Override + public void execute(IngredientsList il, DishList dl, OrderList orderList, Ui ui, FridgeStorage fs, OrderStorage orderStorage) throws DukeException { + System.out.println("\t Are you sure you want to clear all orders in the order list? [y/n]"); + String command = ui.readCommand(); + if(command.toLowerCase().equals("y")){ + ui.showLine(); + orderList.clearList(); + orderStorage.clearInfoForFile(); + System.out.println("\t ORDER LIST CLEARED"); + System.out.println("\n\t Continue by adding order. Template:"); + System.out.println("\t add [-d ORDER_DATE-(dd/mm/yyyy)] -n DISH1_NAME[*DISH_AMOUNT], DISH2_NAME[*DISH_AMOUNT]"); + ui.showLine(); + } else if(command.toLowerCase().equals("n")){ + ui.showLine(); + System.out.println("\t ORDER LIST NOT CLEARED"); + System.out.println("\n\t Continue by adding, removing, altering, listing order."); + System.out.println("\t Type 'template' to see the format of the commands"); + ui.showLine(); + } else { throw new DukeException("Please enter y or n after 'init' command"); } + + } + +} diff --git a/src/main/java/duke/command/orderCommand/ListOrderCmd.java b/src/main/java/duke/command/orderCommand/ListOrderCmd.java deleted file mode 100644 index 6485c051..00000000 --- a/src/main/java/duke/command/orderCommand/ListOrderCmd.java +++ /dev/null @@ -1,48 +0,0 @@ -package duke.command.orderCommand; - -import duke.command.Cmd; -import duke.exception.DukeException; -import duke.list.GenericList; -import duke.order.Order; -import duke.order.OrderList; -import duke.storage.Storage; -import duke.ui.Ui; - -import java.util.List; - -/** - * Represents a specific {@link Cmd} used to list all the {@link Order}s in the {@link OrderList}. - * - */ -public class ListOrderCmd extends Cmd { - - private String listType; - - /** - * the constructor method of {@link ListOrderCmd} - * @param command type of list: list all orders, list all undone orders, - * list all today's orders, list all undone today's orders. - */ - public ListOrderCmd(String command) { - this.listType = command; - } - - @Override - public void execute(GenericList orderList, Ui ui, Storage storage) throws DukeException { - List tmp = null; - if (listType == "undone") { - tmp = ((OrderList)orderList).getAllUndoneOrders(); - } else if (listType == "today") { - tmp = ((OrderList)orderList).getTodayOrders(); - } else if (listType == "undoneToday") { - tmp = ((OrderList)orderList).getTodayUndoneOrders(); - } else { tmp = orderList.getAllEntries(); } - if (orderList.size() == 0 || tmp == null) { throw new DukeException("No orders found!");} - System.out.println("\t Here are the orders in the order list:"); - int cnt = 1; - for (Order order: tmp) { // looping to print all the saved orders - ui.showTask("\t " + cnt + "." + order.toString()); - cnt++; - } - } -} diff --git a/src/main/java/duke/command/orderCommand/ListOrderCommand.java b/src/main/java/duke/command/orderCommand/ListOrderCommand.java new file mode 100644 index 00000000..579220f5 --- /dev/null +++ b/src/main/java/duke/command/orderCommand/ListOrderCommand.java @@ -0,0 +1,74 @@ +package duke.command.orderCommand; + +import duke.command.Command; +import duke.command.ingredientCommand.ListCommand; +import duke.dish.DishList; +import duke.exception.DukeException; +import duke.ingredient.IngredientsList; +import duke.order.Order; +import duke.order.OrderList; +import duke.parser.Convert; +import duke.storage.FridgeStorage; +import duke.storage.OrderStorage; +import duke.ui.Ui; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Represents a specific {@link Command} used to list all the {@link Order}s in the {@link OrderList}. + */ +public class ListOrderCommand extends ListCommand { + + private String[] listType; + + /** + * the constructor method of {@link ListOrderCommand} + * @param command type of list: list all orders, list all undone orders, + * list all today's orders, list all undone today's orders. + */ + public ListOrderCommand(String[] command) { + this.listType = command; + } + + @Override + public void execute(IngredientsList il, DishList dl, OrderList orderList, Ui ui, FridgeStorage fs, OrderStorage os) throws DukeException { + if (orderList.size() == 0) { throw new DukeException("No orders in the order list!");} + List filtered = parse(orderList); + ui.showLine(); + if (filtered.size()==0) { throw new DukeException("No orders found");} + else if (filtered.size()==1) { System.out.println("\t Here are the order in the order list:"); } + else System.out.println("\t Here are the orders in the order list:"); + int cnt = 1; + for (Order order: filtered) { // looping to print all the saved orders + ui.showTask("\t " + cnt + "." + order.toString()); + cnt++; + } + ui.showLine(); + } + + public List parse(OrderList orderList) throws DukeException { + if (listType[0].equals("-l")) { + if (listType[1].equals("all")) {return orderList.getAllEntries();} + else if (listType[1].equals("undone")) {return orderList.getAllUndoneOrders();} + else if (listType[1].equals("today")) {return orderList.getTodayOrders();} + else if (listType[1].equals("undoneToday")) {return orderList.getTodayUndoneOrders();} + else {throw new DukeException("Must enter a valid list type");} + } + List tmp = new ArrayList<>(); + if (listType[0].equals("-n")) { + List tmp2 = orderList.findOrderByDishes(listType[1]); + for (Order order: tmp2) { if(!order.isDone()&&order.isToday()) {tmp.add(order);} } + } else if (listType[0].equals("-d")) { + String[] orderAndType = listType[1].split(" -l ",2); + Date date = Convert.stringToDate(orderAndType[0]); + List tmp2 = orderList.findOrderByDate(date); + if (orderAndType.length==1) tmp = tmp2; + else if (orderAndType[1].equals("undone")) { + for (Order order: tmp2) { if(!order.isDone()) tmp.add(order); } + } else { throw new DukeException("Only support find fixed date orders among all/undone orders");} + } else { throw new DukeException("Must follow the format of list command template");} + return tmp; + } +} diff --git a/src/main/java/duke/dish/Dish.java b/src/main/java/duke/dish/Dish.java index 86502edf..e2341e6e 100644 --- a/src/main/java/duke/dish/Dish.java +++ b/src/main/java/duke/dish/Dish.java @@ -4,14 +4,9 @@ import duke.ingredient.IngredientsList; import duke.storage.Printable; -import java.util.ArrayList; -import java.util.List; - public class Dish implements Printable { private String dishname; - private int total = 0; - private float rating = 0; private IngredientsList ingredientsList; public Dish(String name) { @@ -19,40 +14,29 @@ public Dish(String name) { this.ingredientsList = new IngredientsList(); } - public Dish() { - // - } - - public int getTotalNumberOfOrders() { - return total; - } - - public void setNumberOfOrders(int amount) { - total = total + amount; + public int getIngredientSize() { + return ingredientsList.size(); } - public void clearOrders() { - total = 0; + public Ingredient getIngredients(int index) { + return ingredientsList.getEntry(index); } public String getDishname() { return dishname; } - public void setRating(int r) { - rating = (total * rating + r) / total; - } - - public float getRating() { - return rating; - } public void addIngredients(Ingredient ingredients) { ingredientsList.addEntry(ingredients); } public String toString() { - return dishname; + String str = ""; + for (Ingredient i : ingredientsList.getAllEntries()) { + str += i.getName() + ","; + } + return str; } @Override diff --git a/src/main/java/duke/dish/DishList.java b/src/main/java/duke/dish/DishList.java index 73c67e8c..6074b268 100644 --- a/src/main/java/duke/dish/DishList.java +++ b/src/main/java/duke/dish/DishList.java @@ -2,12 +2,10 @@ import duke.list.GenericList; -import java.util.ArrayList; import java.util.List; public class DishList extends GenericList { - public DishList(List dishList){ super(dishList); } @@ -15,5 +13,4 @@ public DishList(List dishList){ public DishList() { super(); } - } diff --git a/src/main/java/duke/exception/DukeException.java b/src/main/java/duke/exception/DukeException.java index 8272747b..d8152c6f 100644 --- a/src/main/java/duke/exception/DukeException.java +++ b/src/main/java/duke/exception/DukeException.java @@ -6,6 +6,6 @@ public class DukeException extends Exception { public DukeException(String message) { - super("\t ☹ OOPS!!! " + message+". \n\tYou can type: \n\t'template' to see the format of the commands, \n\t'back' to see all your options, \n\t'q' to exit"); + super("\t OOPS!!! " + message+". \n\t You can type: \n\t 'template' to see the format of the commands, \n\t 'back' to see all your options, \n\t 'q' to exit"); } } diff --git a/src/main/java/duke/fridge/diagram.uml b/src/main/java/duke/fridge/diagram.uml index 1d36968d..8a42c9e6 100644 --- a/src/main/java/duke/fridge/diagram.uml +++ b/src/main/java/duke/fridge/diagram.uml @@ -28,7 +28,7 @@ duke.command.dishesCommand.ListDishCommand duke.command.ingredientCommand.FindToday duke.command.ingredientCommand.DeleteCommand - duke.command.dishesCommand.InitCommand + duke.command.dishesCommand.ResetDishCommand duke.list.GenericList duke.command.ingredientCommand.DoneCommand duke.parser.Convert @@ -151,7 +151,7 @@ - + @@ -160,7 +160,13 @@ - + + Fields + Constructors + Methods + Properties + Inner Classes + All private diff --git a/src/main/java/duke/ingredient/Ingredient.java b/src/main/java/duke/ingredient/Ingredient.java index 5a126481..9de0a4dd 100644 --- a/src/main/java/duke/ingredient/Ingredient.java +++ b/src/main/java/duke/ingredient/Ingredient.java @@ -4,16 +4,15 @@ import duke.parser.Convert; import duke.storage.Printable; +import java.text.SimpleDateFormat; import java.util.Date; public class Ingredient implements Printable { - private Integer Nb; private String name; private int amount; private Date expiryDate; private String dateAsString; - public Ingredient(String name, Integer amount, Date expiryDate) throws DukeException //beef 200 19/07/2019 { this.name = name; @@ -28,6 +27,9 @@ public Ingredient(String name, Integer amount, String expiryDate) throws DukeExc dateAsString = expiryDate; } + public Date getDate() { + return expiryDate; + } public int getAmount() { return amount; } @@ -75,6 +77,15 @@ public boolean isExpired() { return !expiryDate.after(new Date()); } + public boolean isExpiredToday(String DateInQuestion){ + + Date today = new Date(); + String pattern = "dd/MM/yyyy"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); + String TodayDate = simpleDateFormat.format(today); + return ((DateInQuestion).equals(TodayDate)); + } + public boolean equalsCompletely(Ingredient other) { return this.equals(other) && this.getExpiryDate().equals(other.getExpiryDate()); } @@ -82,7 +93,6 @@ public boolean equalsCompletely(Ingredient other) { public String printInFile() { return this.getName() + "|" + this.getAmount() + "|" + dateAsString; } - //private String pattern = "dd/MM/yyyy"; - //private SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); - //private String TodayDate = simpleDateFormat.format(today); + + } diff --git a/src/main/java/duke/ingredient/IngredientsList.java b/src/main/java/duke/ingredient/IngredientsList.java index 5ed068fd..7bee39e3 100644 --- a/src/main/java/duke/ingredient/IngredientsList.java +++ b/src/main/java/duke/ingredient/IngredientsList.java @@ -8,6 +8,7 @@ import java.util.List; public class IngredientsList extends GenericList { + public IngredientsList(List ingredientsList) { super(ingredientsList); sortByExpiryDate(); @@ -19,7 +20,6 @@ public IngredientsList() { public void changeIngredientsDate(int Nb, Date date) throws DukeException { genList.get(Nb).changeDate(date); - } @Override @@ -34,18 +34,20 @@ public void addEntry(Ingredient ingredient) { public boolean hasEnough(Ingredient ingredient) { int currAmount = 0; - for (Ingredient ing : getAllEntries()) { - if (ing.equals(ingredient)&&!ing.isExpired()) - currAmount += ing.getAmount(); + for (Ingredient ing : getAllEntries()) { //for all ingredients, + if (ing.equals(ingredient)&&!ing.isExpired()) //if they are the ingredient we want, and it has not expired, + currAmount += ing.getAmount(); //adds into count } - return ingredient.getAmount() <= currAmount; + return ingredient.getAmount() <= currAmount; //if needed amount is less than or equal to amount we have, means we have enough // return getAllEntries().contains(ingredient); } + public void changeName(int Nb, String name) { genList.get(Nb).setName(name); } + public void changeAmount(int Nb, Integer amount) { genList.get(Nb).changeAmount(amount); } @@ -107,4 +109,3 @@ public boolean removeEntry(Ingredient ingredient) throws DukeException { return true; } } - diff --git a/src/main/java/duke/list/GenericList.java b/src/main/java/duke/list/GenericList.java index 7a296c9a..2519d0d7 100644 --- a/src/main/java/duke/list/GenericList.java +++ b/src/main/java/duke/list/GenericList.java @@ -89,6 +89,7 @@ public T getEntry(T entry) { return null; } + public void sort(Comparator comparator) { genList.sort(comparator); } @@ -96,5 +97,4 @@ public void sort(Comparator comparator) { public void clearList() { genList.clear(); } - } diff --git a/src/main/java/duke/list/TodayTodoList.java b/src/main/java/duke/list/TodayTodoList.java new file mode 100644 index 00000000..da5e4a01 --- /dev/null +++ b/src/main/java/duke/list/TodayTodoList.java @@ -0,0 +1,73 @@ +package duke.list; + +import duke.exception.DukeException; +import duke.order.Order; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class TodayTodoList { + private Map tasks; + + public TodayTodoList() { + this.tasks = new LinkedHashMap<>(); + } + + public TodayTodoList(List orderList) { + this.tasks = new LinkedHashMap<>(); + for (Order order: orderList) { + addTodoFromOrder(order); + } + } + + public void addTodo(String dish, int addAmount) { + if (!tasks.containsKey(dish)) tasks.put(dish, addAmount); + else { + int oldAmount = tasks.get(dish); + tasks.put(dish, oldAmount+addAmount); + } + } + + public void deleteTodo(String dish, int delAmount) throws DukeException { + if (!tasks.containsKey(dish)) { throw new DukeException("Error when deleting the task: cannot find dishes in todo list"); } + int oldAmount = tasks.get(dish); + if ((oldAmount-delAmount)<0) { throw new DukeException("Error when deleting the task: removing amount exceed actual"); } + else if (oldAmount==delAmount) tasks.remove(dish); + else tasks.put(dish, oldAmount-delAmount); + } + + public void addTodoFromOrder(Order order) { + if (!order.isDone()) { + for (Map.Entry entry : order.getOrderContent().entrySet()) { + String dishName = entry.getKey(); + int amount = entry.getValue(); + addTodo(dishName, amount); + } + } + } + + public void deleteTodoFromOrder(Order order) throws DukeException { + if (!order.isDone()) System.out.println("\t Warning: Deleting undone dishes from todo list"); + for (Map.Entry entry : order.getOrderContent().entrySet()) { + String dishName = entry.getKey(); + int amount = entry.getValue(); + deleteTodo(dishName, amount); + } + } + + public String toString() { + Date date = new Date(); + String output="\t Today Task list ("+date+")"; + int cnt=0; + for (Map.Entry entry : tasks.entrySet()) { + cnt++; + String dishName = entry.getKey(); + int amount = entry.getValue(); + output+="\n\t "+ cnt+". "+dishName+" (amount: "+amount+") "; + } + return output; + } + +} diff --git a/src/main/java/duke/order/Order.java b/src/main/java/duke/order/Order.java index 204db881..71ea9f11 100644 --- a/src/main/java/duke/order/Order.java +++ b/src/main/java/duke/order/Order.java @@ -1,23 +1,22 @@ package duke.order; -import duke.dish.Dish; import duke.Duke; import duke.exception.DukeException; -import duke.parser.Convert; import duke.storage.Printable; -import java.time.Instant; -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.*; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.Map; /** * Represents a general Order to be added by {@link Duke}. */ public class Order implements Printable { - private Map content; + private Map content; private boolean isDone; private Date date; + private String dateToString; /** * The constructor method for {@link Order}. @@ -25,39 +24,44 @@ public class Order implements Printable { public Order() { this.isDone = false; this.date = new Date(); - this.content = new HashMap<>(); + this.content = new LinkedHashMap<>(); + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + this.dateToString = simpleDateFormat.format(this.date); } /** * The constructor method for the {@link Order} in reservation case. * @param date date of serving the {@link Order}. */ - public Order(String date) { - this.date = (date=="")? new Date():Convert.stringToDate(date); + public Order(Date date) { + if (date.before(new Date())) {date = new Date();} + this.date = date; this.isDone = false; - this.content = new HashMap<>(); + this.content = new LinkedHashMap<>(); + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + this.dateToString = simpleDateFormat.format(this.date); + } /** * Used to get the serving date of the {@link Order}. */ - public Date getDate() { return this.date;} + public String getDate() { return this.dateToString;} /** * Used to alter the serving date of the {@link Order}. * @param date reset date of the {@link Order}. */ - public void setDate(String date) throws DukeException { - try { - Date setDate = Convert.stringToDate(date); - Date todayDate = new Date(); - if (setDate.before(todayDate)) { - throw new DukeException("Date invalid!"); - } - } catch (Exception e) { - e.printStackTrace(); - } - + public void setDate(Date date) throws DukeException { + Date setDate = date; + Date todayDate = new Date(); + if (setDate.before(todayDate)) { throw new DukeException("Must set date equal or after today"); } + this.date = setDate; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + String setDateToString = simpleDateFormat.format(setDate); + this.dateToString = setDateToString; } /** @@ -66,12 +70,11 @@ public void setDate(String date) throws DukeException { * @return boolean true if it is today's order, false otherwise (i.e., pre-order) */ public boolean isToday() { - LocalDate todayDate = LocalDate.now(); - Instant instant = date.toInstant(); - ZoneId zoneId = ZoneId.systemDefault(); - LocalDate orderDate = instant.atZone(zoneId).toLocalDate(); - if (todayDate==orderDate) return true; - return false; + Date today = new Date(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + String todayToString = simpleDateFormat.format(today); + if (this.dateToString.equals(todayToString)) { return true;} + else return false; } /** @@ -99,7 +102,7 @@ public String getStatusIcon() { * Returns the content of the {@link Order}. * @return content of the Order */ - public Map getOrderContent() { return this.content; } + public Map getOrderContent() { return this.content; } /** * Returns the content of the {@link Order} @@ -108,14 +111,15 @@ public String getStatusIcon() { */ public String toString() { String description; -// description = "["+this.getStatusIcon()+"] Order at " + this.date + ": "; description = "["+this.getStatusIcon()+"] "; - if (this.isToday()) description += "Order today: "; - else description += "Order at " + this.date + ": "; - for (Map.Entry entry : content.entrySet()) { - Dish dish = entry.getKey(); + if (this.isToday()) { description += "Order today "; } + else { description += "Order /on " + dateToString + " "; } + int count=0; + for (Map.Entry entry : content.entrySet()) { + String dishName = entry.getKey(); int amount = entry.getValue(); - description += "\n"+" - " + amount + " \u2718 " + dish.getDishname(); + count++; + description += "\n\t"+" (" + count + ") " + dishName + " " + amount; } return description; } @@ -127,12 +131,12 @@ public String toString() { */ public String printInFile() { String description; - if (this.isDone()) { description = "O|1|" + this.date; } - else { description = "O|0|" + this.date; } - for (Map.Entry entry : content.entrySet()) { - Dish dish = entry.getKey(); + if (this.isDone()) { description = "1|" + dateToString; } + else { description = "0|" + dateToString; } + for (Map.Entry entry : content.entrySet()) { + String dishName = entry.getKey(); int amount = entry.getValue(); - description += "\nD|" +dish.getDishname() + "|" + amount; + description += "|D|" + dishName + "|" + amount; } return description; } @@ -141,14 +145,14 @@ public String printInFile() { * Returns a boolean indicating whether the {@link Order} has that dishes. * @return boolean true if the order has that dishes, false otherwise. */ - public boolean hasDishes(Dish dishes) { return content.containsKey(dishes); } + public boolean hasDishes(String dishes) { return content.containsKey(dishes); } /** * Returns the amount of the dishes ordered in the {@link Order} * @param dishes dishes * @return dishes amount */ - public int getDishesAmount(Dish dishes) { + public int getDishesAmount(String dishes) { if (this.hasDishes(dishes)) { return content.get(dishes); } else {return 0; } @@ -161,7 +165,7 @@ public int getDishesAmount(Dish dishes) { * simply add a new element in the content map. * If the order is done, do nothing. */ - public void addDish(Dish dishes){ + public void addDish(String dishes){ if (!this.isDone()) if (!this.hasDishes(dishes)) { content.put(dishes, 1); @@ -177,7 +181,7 @@ public void addDish(Dish dishes){ * simply add a new element in the content map. * If the order is done, do nothing. */ - public void addDish(Dish dishes, int addAmount){ + public void addDish(String dishes, int addAmount){ if (!this.isDone()) if (!content.containsKey(dishes)) { content.put(dishes, addAmount); @@ -187,22 +191,6 @@ public void addDish(Dish dishes, int addAmount){ } } -// useless feature (keep it now, will delete if still unnecessary in later phase) -// public double getTotalPrice() { -// //To do -// //link the price with DishNb s.t. can calculate total price -// int unitPrice = 1; -// -// double total = 0; -// for (Map.Entry entry : content.entrySet()) { -// Dishes dish = entry.getKey(); -// int amount = entry.getValue(); -// total += amount*unitPrice; -// } -// return total; -// } - - } diff --git a/src/main/java/duke/order/OrderList.java b/src/main/java/duke/order/OrderList.java index a43a0ae8..46cb116d 100644 --- a/src/main/java/duke/order/OrderList.java +++ b/src/main/java/duke/order/OrderList.java @@ -2,11 +2,12 @@ import duke.Duke; import duke.exception.DukeException; - import duke.list.GenericList; -import duke.dish.Dish; +import duke.list.TodayTodoList; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -14,11 +15,14 @@ */ public class OrderList extends GenericList { + private TodayTodoList todoList; + /** * The constructor method(1) for OrderList. */ public OrderList() { super(); + this.todoList = new TodayTodoList(); } /** @@ -26,6 +30,7 @@ public OrderList() { */ public OrderList(List orderList) { super(orderList); + this.todoList = new TodayTodoList(orderList); } @@ -38,14 +43,13 @@ public void markOrderDone(int orderNb) { } - /** * Returns a list of all the undone {@link Order}s in the {@link OrderList}. * Not including orders that has been done. * @return {@link ArrayList} of {@link Order} */ public List getAllUndoneOrders() { - List undoneOrderList = null; + List undoneOrderList = new ArrayList<>(); for (Order order : genList) { if (!order.isDone()) { undoneOrderList.add(order); @@ -59,20 +63,44 @@ public List getAllUndoneOrders() { * @return {@link ArrayList} of {@link Order} */ public List getTodayOrders() { - List todayOrderList = null; + List todayOrderList = new ArrayList<>(); for (Order order : genList) { if (order.isToday()) { todayOrderList.add(order); } } return todayOrderList; } + /** + * Returns a list of all the {@link Order}s on some date in the {@link OrderList}. + * @return {@link ArrayList} of {@link Order} + */ + public List findOrderByDate(Date queryDate) { + List theOrderList = new ArrayList<>(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); + String qDate = simpleDateFormat.format(queryDate); + for (Order order : genList) { if (qDate.equals(order.getDate())) { theOrderList.add(order); } } + return theOrderList; + } + + /** + * Returns a list of all the {@link Order}s containing some dishes in the {@link OrderList}. + * @return {@link ArrayList} of {@link Order} + */ + public List findOrderByDishes(String dishName) { + List theOrderList = new ArrayList<>(); + for (Order order : genList) { + if (order.hasDishes(dishName)) { theOrderList.add(order); } + } + return theOrderList; + } + /** * Returns a list of all the undone {@link Order}s today * in the {@link OrderList}. * @return {@link ArrayList} of {@link Order} */ public List getTodayUndoneOrders() { - List todayOrderList = null; + List todayOrderList = new ArrayList<>(); for (Order order : genList) { if (order.isToday()&&(!order.isDone())) { todayOrderList.add(order); @@ -87,7 +115,7 @@ public List getTodayUndoneOrders() { * @param newDate reset date of the {@link Order}. * @throws DukeException if the date is before the date today. */ - public void changeOrderDate(int orderNb, String newDate) throws DukeException { + public void changeOrderDate(int orderNb, Date newDate) throws DukeException { genList.get(orderNb).setDate(newDate); } @@ -95,33 +123,38 @@ public void changeOrderDate(int orderNb, String newDate) throws DukeException { * Add dishes to the {@link Order}. * Add one more if not specifying the amount. * @param orderNb order index - * @param dish dishes + * @param dishName dishes */ - public void addOrderDish(int orderNb, Dish dish) { - genList.get(orderNb).addDish(dish); + public void addOrderDish(int orderNb, String dishName) { + genList.get(orderNb).addDish(dishName); } /** * Add dishes to the {@link Order}. * @param orderNb order index - * @param dish dishes + * @param dishName dishes * @param amount add amount of that dishes */ - public void addOrderDish(int orderNb, Dish dish, int amount) { - genList.get(orderNb).addDish(dish, amount); + public void addOrderDish(int orderNb, String dishName, int amount) { + genList.get(orderNb).addDish(dishName, amount); } /** * Find dishes amount in the {@link Order}. * @param orderNb order index - * @param dishes dishes + * @param dishName dishes * @return the amount of that dishes */ - public int findDishesAmount(int orderNb, Dish dishes) { - return genList.get(orderNb).getDishesAmount(dishes); + public int findDishesAmount(int orderNb, String dishName) { + return genList.get(orderNb).getDishesAmount(dishName); } - + /** + * @return the description of the chef's To'do list today as a string + */ + public String todoListToString() { + return todoList.toString(); + } } diff --git a/src/main/java/duke/parser/Convert.java b/src/main/java/duke/parser/Convert.java index 1dcef58f..5afa4ca3 100644 --- a/src/main/java/duke/parser/Convert.java +++ b/src/main/java/duke/parser/Convert.java @@ -1,5 +1,7 @@ package duke.parser; +import duke.exception.DukeException; + import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -40,17 +42,18 @@ public static String getDaySuffix(int n) { * @param date String in the format "dd/MM/yyyy hhmm" or "dd/MM/yyyy", used to extract a {@link Date} instance from * @return The {@link Date} instance created from the argument string or null */ - public static Date stringToDate(String date) { + public static Date stringToDate(String date) throws DukeException { DateFormat formatter; if (date.length() > 11) { formatter = new SimpleDateFormat("dd/MM/yyyy hhmm"); } else { formatter = new SimpleDateFormat("dd/MM/yyyy"); } + checkValidDate(date); try { return formatter.parse(date); } catch (ParseException e) { - System.out.println("Warning: Unable to convert \"" + date + "\" to a Date."); + System.out.println("\t Warning: Unable to convert \"" + date + "\" to a Date."); return null; } } @@ -76,4 +79,23 @@ public static String getDateString(Date date, String dateString) { SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(date); } + + public static void checkValidDate(String date) throws DukeException { + boolean flag = true; + String[] dateMonthYear = date.split("\\/",3); + if (dateMonthYear.length!=3) { + throw new DukeException("Invalid date"); + } else { + try{ + int dd = Integer.parseInt(dateMonthYear[0]); + int mm = Integer.parseInt(dateMonthYear[1]); + int yy = Integer.parseInt(dateMonthYear[2]); + if (dd<1||dd>31||mm<1||mm>12||yy<1000||yy>9999) throw new DukeException("Must enter a valid date"); + if (mm==2&&(dd==31||dd==30||dd==29)) throw new DukeException("Must enter a valid date"); + if (dd==31&&(mm==4||mm==6||mm==9||mm==11)) throw new DukeException("Must enter a valid date"); + } catch (NumberFormatException e) { + e.getStackTrace(); + } + } + } } diff --git a/src/main/java/duke/parser/Parser.java b/src/main/java/duke/parser/Parser.java index 73cd68f8..6f519351 100644 --- a/src/main/java/duke/parser/Parser.java +++ b/src/main/java/duke/parser/Parser.java @@ -1,10 +1,10 @@ package duke.parser; import duke.Duke; -import duke.command.Cmd; -import duke.command.ingredientCommand.AddCommand; -import duke.command.ingredientCommand.DeleteCommand; -import duke.command.ingredientCommand.UseCommand; +import duke.command.Command; +import duke.command.dishesCommand.*; +import duke.command.ingredientCommand.*; +import duke.command.orderCommand.*; import duke.dish.Dish; import duke.exception.DukeException; import duke.ingredient.Ingredient; @@ -14,7 +14,6 @@ /** * Represents a parser used to parse the input String from the user into a Duke understandable Command. - *

* It should deals with making sense of the user command. */ public class Parser { @@ -22,7 +21,7 @@ public class Parser { //There is no constructor method for all others are static. /** - * Returns a {@link Cmd} that can be understood by {@link Duke} and executed after. + * Returns a {@link Command} that can be understood by {@link Duke} and executed after. * We first split the fullCommand into 2, the keyword, followed by everything else. * Then we perform switching based on the keyword. * @@ -30,159 +29,99 @@ public class Parser { * @return Command The Command to be executed * @throws DukeException for any invalid input */ - /* public static Cmd parse(String fullCommand, int size) throws DukeException { - //splitted contains the keyword and the rest (description or task number) - String[] splitted = fullCommand.split(" ", 2); - //switching on the keyword - switch (splitted[0]) { - case "list": - return new ListCommand(); - case "listtoday": - return new FindToday(); - case "bye": - return new ExitCommand(); - case "done": - checkLength(splitted); - return new DoneCommand(checkNumber(splitted[1], size)); - case "todo": - checkLength(splitted); - return new AddCommand(new Todo(splitted[1])); - case "deadline": - checkLength(splitted); - String[] getBy = splitAndCheck(splitted[1], " /by "); - return new AddCommand(new Deadline(getBy[0], getBy[1])); - case "event": - checkLength(splitted); - String[] getAt = splitAndCheck(splitted[1], " /at "); - return new AddCommand(new Event(getAt[0], getAt[1])); - case "find": - checkLength(splitted); - return new FindIngredientCommand(splitted[1]); - case "delete": - checkLength(splitted); - return new DeleteCommand(checkNumber(splitted[1], size)); - case "remind": - return new RemindCommand(); - case "snooze": - checkLength(splitted); - String[] getUntil = splitAndCheck(splitted[1], " /until "); - return new Snooze(checkNumber(getUntil[0], size), getUntil[1]); - case "view": - checkLength(splitted); - Date splittedDate = Convert.stringToDate(splitted[1]); - return new ViewCommand(splittedDate); - case "period": - checkLength(splitted); - String[] getPart = splitAndCheck(splitted[1], " /from "); - String[] part = splitAndCheck(getPart[1], " /to "); - return new AddCommand(new DoWithinPeriodTasks(getPart[0], part[0], part[1])); - default: - throw new DukeException("I'm sorry, but I don't know what that means :-("); - } - } -*/ - public static Cmd parse(String fullCommand, Duke.Type type) throws DukeException { + public static Command parse(String fullCommand, Duke.Type type) throws DukeException { String[] splitted; - //= fullCommand.split(" ", 3); - + switch (type) { + case INGREDIENT: { + splitted = fullCommand.split(" "); - switch (type) { - case INGREDIENT: { - splitted = fullCommand.split(" "); - - if (splitted[0].equals("add")) { - if (splitted.length != 4 ) - throw new DukeException("must specify ingredient name, amount and/or expiry date"); - return new AddCommand(new Ingredient(splitted[1], Integer.parseInt(splitted[2]), splitted[3])); - }if (splitted[0].equals("remove")) { - if(splitted.length!=2) - throw new DukeException("must specify a index"); - return new DeleteCommand(Integer.parseInt(splitted[1])); - } else if (splitted[0].equals("use")) { - if(splitted.length!=3) - throw new DukeException("follow the template: use "); - return new UseCommand(new Ingredient(splitted[1], Integer.parseInt(splitted[2]), new Date())); - } else - throw new DukeException("not a valid command for an Ingredient"); - + if (splitted[0].equals("add")) { + if (splitted.length != 4) + throw new DukeException("must specify ingredient name, amount and/or expiry date"); + return new AddCommand(new Ingredient(splitted[1], Integer.parseInt(splitted[2]), splitted[3])); } - case DISH: { - splitted = fullCommand.split(" ", 4); - if (splitted.length > 4) - throw new DukeException("must specify ing name, amount and expiry date"); - else if (splitted[0].equals("add")) - return new AddCommand(new Dish(splitted[1])); - if (splitted[0].equals("remove")) { - return new DeleteCommand(Integer.parseInt(splitted[1])); - } else - throw new DukeException("not a valid command for an Ingredient"); - + if (splitted[0].equals("remove")) { + if (splitted.length != 2) + throw new DukeException("must specify a index"); + return new DeleteCommand(Integer.parseInt(splitted[1])); + } else if (splitted[0].equals("use")) { + if (splitted.length != 3) + throw new DukeException("follow the template: use "); + return new UseCommand(new Ingredient(splitted[1], Integer.parseInt(splitted[2]), new Date())); + } else if (splitted[0].equals("listtoday")) { + if (splitted.length != 1) + throw new DukeException("follow the template: listtoday"); + return new FindToday(); + } else if(splitted[0].equals("find")) { + if(splitted.length != 2) + throw new DukeException("follow the template: find "); + return new FindIngredientCommand(splitted[1]); } - case ORDER: { - splitted = fullCommand.split(" ", 4); - if (splitted.length > 4) - throw new DukeException("must specify order name, amount and expiry date"); - else if (splitted[0].equals("add")) - return new AddCommand(new Order(splitted[1])); - if (splitted[0].equals("remove")) { - // for(int i=0) - return new DeleteCommand(Integer.parseInt(splitted[1])); - } else - throw new DukeException("not a valid command for an Ingredient"); - - } - default: - throw new DukeException("not a valid type"); + else + throw new DukeException("not a valid command for an Ingredient"); } + case DISH: { + splitted = fullCommand.split(" ", 2); + switch (splitted[0]) { + case "add": + if(splitted.length < 2) { + throw new DukeException("specify dish name"); + } + else + splitted[1] = splitted[1].replaceAll("\\s+", " "); + return new AddDishCommand(new Dish(splitted[1])); + case "remove": + try { + return new DeleteDishCommand(Integer.parseInt(splitted[1])); + } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { + throw new DukeException("enter a valid index"); + } + case "list": + return new ListDishCommand(); + case "initialize": + return new ResetDishCommand(); + case "ingredient": + String[] getIng = splitted[1].split(" ", 3); + int amount = 0; + int index = 0; + try { + amount = Integer.parseInt(getIng[1]); + index = Integer.parseInt(getIng[2]); + } catch (NumberFormatException e) { + throw new DukeException("enter a valid amount/index"); + } + return new AddIngredient(new Ingredient(getIng[0], amount, new Date()), index); + default: + throw new DukeException("not a valid command for a Dish"); + } + } + case ORDER: { + splitted = fullCommand.split(" ", 2); + if (splitted.length > 4) + throw new DukeException("must specify ordered dishes and order date"); + else if (splitted[0].equals("add")){ //add a new order + return addOrderParser(splitted); + } else if (splitted[0].equals("alter")) { //alter order date + return alterOrderDateParser(splitted); + } else if (splitted[0].equals("remove") ||splitted[0].equals("done")) { //remove or done an order + return removeOrDoneOrderParser(splitted); + } else if (splitted[0].equals("init")) { + return new InitOrderListCommand(); + } else if (splitted[0].equals("list")) {//list orders + String[] listType; + if (splitted.length == 1) { + listType = "-l all".split(" ",2); + } else listType = splitted[1].split(" ",2); + if (listType.length==1) {throw new DukeException("Must enter a list type, dishes name, or order date");} + return new ListOrderCommand(listType); + } else throw new DukeException("Not a valid command for an order"); + } + default: + throw new DukeException("not a valid type"); + } } -// public static Cmd parse(String fullCommand) throws DukeException { -// //splitted contains the keyword and the rest (description or task number) -// String[] splitted = fullCommand.split(" ", 2); -// //switching on the keyword -// switch (splitted[0]) { -// //RecipeCommand -// case "dishadd": -// String[] getnum = splitAndCheck(splitted[1], " /num "); -// int amount = Integer.parseInt(getnum[1]); -// return new AddDishCommand(new Dish(getnum[0]), amount); -// case "dishlist": -// return new ListDishCommand(); -// case "dishdelete" : -// int Nb = Integer.parseInt(splitted[1]); -// return new DeleteDishCommand(Nb); -// case "addingredient" : -// String[] getIng = splitAndCheck(splitted[1], " /add "); -// int listNum = Integer.parseInt(getIng[1]); -// return new AddIngredient(new Ingredient(getIng[0], listNum, new Date()) , listNum); -// case "dishinit" : -// return new InitCommand(); -// // OrderCommand -// case "orderAdd": -// return new AddOrder(); -// case "orderList": -// // splitted[1] can be orderList all, orderList undone, -// // orderList today, orderList undoneToday -// checkLength(splitted); -// return new ListOrderCmd(splitted[1]); -// case "orderDone": -// checkLength(splitted); -// return new DoneOrderCmd(splitted[1]); -// case "orderCancel": -// return new CancelOrderCmd(splitted[1]); -// case "orderAlterDate": -// checkLength(splitted); -// String[] getDate = splitAndCheck(splitted[1], " /to "); -// // getDate[0] is the order index, getDate[1] is the newly set date -// return new AlterServingDateCmd(Integer.parseInt(getDate[0]), getDate[1]); -// case "orderFindDate": -// return new FindOrderByDate(splitted[1]); -// default: -// throw new DukeException("I'm sorry, but I don't know what that means :-("); -// } - // } - /** * Checks the length of a String array is of size 2. @@ -225,5 +164,71 @@ public static int checkNumber(String str, int size) throws DukeException { } return x; } -} + public static Command addOrderParser(String[] splitter) throws DukeException { + Order newOrder; + Date orderDate; + String[] orderedDishes; + if (splitter[1].startsWith("-n ")) { + if (splitter[1].length()<4) { throw new DukeException("Must specify dishes name"); } + newOrder = new Order(); + orderedDishes = splitter[1].substring(3).split(", "); + } else if (splitter[1].startsWith("-d ")&&splitter[1].length()>20) { + String[] dateAndDish = splitter[1].substring(3).split(" -n ",2); + if (dateAndDish[0].length()!=10) { throw new DukeException("Must enter a valid order date: dd/mm/yyyy"); } + orderDate = Convert.stringToDate(dateAndDish[0]); + newOrder = new Order(orderDate); + orderedDishes = dateAndDish[1].split(", "); + } else { throw new DukeException("must enter a valid order date or specify dishes"); } + for (String dishes: orderedDishes) { + String[] dishesSplit = dishes.split("\\*", 2); + if (dishesSplit.length==1) newOrder.addDish(dishesSplit[0], 1); + else { + int dishAmount; + try{ + dishAmount = Integer.parseInt(dishesSplit[1]); + if (dishAmount<=0) {throw new DukeException("Must enter a dishes amount larger than 1");} + } catch (NumberFormatException e) { + throw new DukeException("cannot resolve non-integer or too large dishes amount"); + } + newOrder.addDish(dishesSplit[0], dishAmount); + } + } + return new AddOrderCommand(newOrder); + } + + public static Command alterOrderDateParser(String[] splitter) throws DukeException { + if (splitter.length == 1) { + throw new DukeException("Must enter an order index.\n\t Note that ORDER_INDEX starts from 1"); + } + String[] indexAndDate = splitter[1].split(" ", 2); + int orderIndex; + Date orderDate; + try { + orderIndex = Integer.parseInt(indexAndDate[0]); + if (orderIndex <= 0) throw new DukeException("Must enter a positive order index"); + } catch (NumberFormatException e) { + throw new DukeException("Must enter a valid order index"); + } + if (indexAndDate.length == 1) { orderDate = new Date(); } + else { + orderDate = Convert.stringToDate(indexAndDate[1]); + if (orderDate==null) {throw new DukeException("Error when converting order date");} + } + return new AlterDateCommand(orderIndex-1, orderDate); + } + + public static Command removeOrDoneOrderParser(String[] splitter) throws DukeException { + if (splitter.length == 1) { + throw new DukeException("Must enter an order index.\n\t Note that ORDER_INDEX starts from 1"); + } + try { + int orderIndex = Integer.parseInt(splitter[1]); + if (orderIndex <= 0) throw new DukeException("Must enter a positive order index"); + if (splitter[0].equals("remove")) return new DeleteOrderCommand(orderIndex - 1); + else return new DoneOrderCommand(orderIndex - 1); + } catch (NumberFormatException e) { + throw new DukeException("Must enter a valid order index"); + } + } +} \ No newline at end of file diff --git a/src/main/java/duke/storage/OrderStorage.java b/src/main/java/duke/storage/OrderStorage.java index 25272b22..15405a49 100644 --- a/src/main/java/duke/storage/OrderStorage.java +++ b/src/main/java/duke/storage/OrderStorage.java @@ -1,9 +1,17 @@ package duke.storage; import duke.exception.DukeException; -import duke.ingredient.Ingredient; import duke.list.GenericList; import duke.order.Order; +import duke.order.OrderList; +import duke.parser.Convert; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Date; public class OrderStorage extends Storage { /** @@ -11,20 +19,41 @@ public class OrderStorage extends Storage { * * @param fp used to specify the location of the file in the hard disc. */ - public OrderStorage(String fp) { + public OrderStorage(String fp) throws DukeException { super(fp); + entries = load(); } @Override GenericList generate() throws DukeException { + entries = new OrderList(); for (String next : contentSoFar) { - //splitting each line to extract the task: - //type - words[0], done or not - words[1], description - words[2], and more. - String[] words = next.split("\\|"); - if(words.length!=3) - throw new DukeException("Error while reading from the order Storage"); - entries.addEntry(new Order()); + String[] words = next.split("\\|",3); + if(words.length!=3) throw new DukeException("Error while reading from the order Storage"); + Date orderDate = Convert.stringToDate(words[1]); + Order tmpOrder = new Order(orderDate); + if (words[0].equals("1")) tmpOrder.markAsDone(); + String[] dishes = words[2].split("D\\|"); + for (String d: dishes) { + if (d=="") continue; + String[] nameAndAmount = d.split("\\|",3); + if (nameAndAmount.length==1) continue; + else { + try { + tmpOrder.addDish(nameAndAmount[0], Integer.parseInt(nameAndAmount[1])); + } catch (NumberFormatException e) { + e.getStackTrace(); + } + } + } + entries.addEntry(tmpOrder); } return entries; } -} + + @Override + public GenericList getEntries() { + return entries; + } + +} \ No newline at end of file diff --git a/src/main/java/duke/storage/Storage.java b/src/main/java/duke/storage/Storage.java index 2268ac7e..e0c13919 100644 --- a/src/main/java/duke/storage/Storage.java +++ b/src/main/java/duke/storage/Storage.java @@ -6,6 +6,7 @@ import duke.task.TaskList; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -56,6 +57,8 @@ public GenericList load() throws DukeException { return entries; } + public GenericList getEntries() { return entries; } + /** * Part of the load method, taken out. * Generates tasks based on contentSoFar. @@ -125,4 +128,17 @@ public void addInFile(String task) throws IOException { Files.write(path, contentSoFar, StandardCharsets.UTF_8); } + /** + * Used to clear all info in the storage file. + */ + public void clearInfoForFile() throws DukeException { + File file = new File(filePath); + try { + if (!file.exists()) { file.createNewFile(); } + FileWriter fileWriter = new FileWriter(file); + fileWriter.write(""); + fileWriter.flush(); + fileWriter.close(); + } catch (IOException e) { throw new DukeException("Error when clearing the list"); } + } } diff --git a/src/main/java/duke/storage/TaskStorage.java b/src/main/java/duke/storage/TaskStorage.java index 9efb5c45..86bfe1bc 100644 --- a/src/main/java/duke/storage/TaskStorage.java +++ b/src/main/java/duke/storage/TaskStorage.java @@ -4,12 +4,6 @@ import duke.list.GenericList; import duke.task.*; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; - public class TaskStorage extends Storage { /** * The constructor method for Storage. diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index 7ed72c66..3ed5f226 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -1,5 +1,6 @@ package duke.task; +import duke.exception.DukeException; import duke.parser.Convert; import java.util.Date; @@ -15,13 +16,13 @@ public class Deadline extends Task { /** * The constructor method for Deadline. */ - public Deadline(String description, String str) { + public Deadline(String description, String str) throws DukeException { super(description); this.setNewDate(str); } @Override - public void setNewDate(String date) { + public void setNewDate(String date) throws DukeException { this.by = date; this.date = Convert.stringToDate(by); } diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index d67e8a2a..80670572 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,5 +1,6 @@ package duke.task; +import duke.exception.DukeException; import duke.parser.Convert; import java.util.Date; @@ -15,13 +16,13 @@ public class Event extends Task { /** * The constructor method for Event. */ - public Event(String description, String str) { + public Event(String description, String str) throws DukeException { super(description); this.setNewDate(str); } @Override - public void setNewDate(String date) { + public void setNewDate(String date) throws DukeException { this.at = date; this.date = Convert.stringToDate(at); } diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index c6d05062..7b17e496 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -1,6 +1,7 @@ package duke.task; import duke.Duke; +import duke.exception.DukeException; import duke.storage.Printable; import java.util.Date; @@ -22,7 +23,7 @@ public Task(String description) { this.isDone = false; } - public abstract void setNewDate(String date); + public abstract void setNewDate(String date) throws DukeException; public abstract Date getCurrentDate(); diff --git a/src/main/java/duke/task/TaskList.java b/src/main/java/duke/task/TaskList.java index dbcb84a8..6abc93c9 100644 --- a/src/main/java/duke/task/TaskList.java +++ b/src/main/java/duke/task/TaskList.java @@ -1,9 +1,9 @@ package duke.task; import duke.Duke; +import duke.exception.DukeException; import duke.list.GenericList; -import java.util.ArrayList; import java.util.List; /** @@ -35,7 +35,7 @@ public void markTaskDone(int taskNb) { genList.get(taskNb).markAsDone(); } - public void changeTaskDate(int taskNb, String date) { + public void changeTaskDate(int taskNb, String date) throws DukeException { genList.get(taskNb).setNewDate(date); } } diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index d7e3f4a1..b7353744 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,18 +1,19 @@ package duke.task; +import duke.exception.DukeException; import duke.parser.Convert; import java.util.Date; /** - * Represents a specific {@link Task} todo, not necessarily indicating a deadline or a specific date. + * This class... */ public class Todo extends Task { private Date date; /** - * The constructor method for Todo. + * The constructor method for this class. */ public Todo(String description) { super(description); @@ -20,7 +21,7 @@ public Todo(String description) { } @Override - public void setNewDate(String date) { + public void setNewDate(String date) throws DukeException { this.date = Convert.stringToDate(date); } diff --git a/src/main/java/duke/ui/Ui.java b/src/main/java/duke/ui/Ui.java index 0c0398b2..b51de552 100644 --- a/src/main/java/duke/ui/Ui.java +++ b/src/main/java/duke/ui/Ui.java @@ -1,9 +1,11 @@ package duke.ui; import duke.Duke; +import duke.dish.Dish; import duke.ingredient.Ingredient; import duke.ingredient.IngredientsList; +import java.io.IOException; import java.util.Calendar; import java.util.Scanner; @@ -13,7 +15,9 @@ public class Ui { private Scanner scanner; - private static final String line = "____________________________________________________________"; + private static final String line = "_________________________________________________________________________________________"; + + private final boolean DRAW = false; /** * The constructor method for Ui. @@ -38,6 +42,59 @@ public void showLine() { System.out.println("\t " + line); } + public void chefDrawing() { + if(!DRAW) return; + System.out.println(" (c)___c____(c) "); + System.out.println(" \\ ........../ "); + System.out.println(" |.........| "); + System.out.println(" |.......| "); + System.out.println(" |.......| "); + System.out.println(" |=======| "); + System.out.println(" |=======| "); + System.out.println(" __o)''''::? "); + System.out.println(" C__ c)::; "); + System.out.println(" >-- :: /\\ "); + System.out.println(" (____/ /__\\ "); + System.out.println(" } /''| |##| "); + System.out.println(" __/ (|V ^ )\\ |##| "); + System.out.println(" o | _____/ |#/ / | |##| "); + System.out.println(" @ o_|}|_____/|/ / | |##| "); + System.out.println(" _____/ / | ~!!~ "); + System.out.println(" ======ooo}{|______)# | /`'\\ "); + System.out.println(" ~~~~ ; ; ###---|8 '' "); + System.out.println(" ____;_____;____ ###==== /:|\\ "); + System.out.println(" (///0///@///@///) ###@@@@| "); + System.out.println(" |~~~~~~~~~~~~~~~| ###@@@@| "); + System.out.println(" \\ / ###@@@@| + "); + System.out.println(" \\___________/ ###xxxxx /\\ // "); + System.out.println(" H H H H ###|| | / \\ // "); + System.out.println(" H H H H | || | /____\\ /~_^_ "); + System.out.println(" H H H H C |C | _|@@|_ /__|#|_ "); + System.out.println(" H H H H || || /_|@@|_/___|#|/| "); + System.out.println(" v \\/ H(o) (o) H || :: |:::::::::::::|#| "); + System.out.println(" ~ ~~ (o) (o) Ccc__)__) | CHEF |#| "); + System.out.println(" \\|/ ~ @* & ~ |:::::::::::::|/ \\|/ "); + System.out.println(" ~ \\|/ !! \\ !/ ~~~~~~~~~~~~~ ~~~ "); + System.out.println(" ~~~ ~~ ~~ ~~ "); + System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); + } + + public void dishDrawing() { + if(!DRAW) return; + System.out.println(" (\\ "); + System.out.println(" \\ \\ "); + System.out.println(" \\/ ___,.-------..__ "); + System.out.println(" //\\\\ _,-'\\\\ `'--._ //\\\\ "); + System.out.println(" \\\\ ;' \\\\ `: // "); + System.out.println(" `( \\\\ )' "); + System.out.println(" :. \\\\,----, ,; "); + System.out.println(" `.`--.___ ( / ___.--',' "); + System.out.println(" `. ``-----'-'' ,' "); + System.out.println(" -. ,- "); + System.out.println(" `-._______.- "); + System.out.println("\n"); + } + /** * Used to print the greeting message from {@link Duke}. */ @@ -45,18 +102,17 @@ public void showWelcome() { showLine(); Calendar c = Calendar.getInstance(); int timeOfDay = c.get(Calendar.HOUR_OF_DAY); - String greeting = "Hello"; - if (timeOfDay >= 0 && timeOfDay < 12) { + String greeting; + if (timeOfDay < 12) { greeting = "Good Morning"; - } else if (timeOfDay >= 12 && timeOfDay < 16) { + } else if (timeOfDay < 16) { greeting = "Good Afternoon"; - } else if (timeOfDay >= 16 && timeOfDay < 21) { + } else if (timeOfDay < 21) { greeting = "Good Evening"; - } else if (timeOfDay >= 21 && timeOfDay < 24) { + } else { greeting = "Good Night"; } System.out.println("\t " + greeting + " chef! I'm Duke"); - } public void showHasExpiring() { @@ -65,12 +121,13 @@ public void showHasExpiring() { } public void showOptions() { - System.out.println("Options (choose one): "); - System.out.println("'a' remove all expiring"); - System.out.println("'b' add/remove/use an ingredient"); - System.out.println("'c' place/remove/change an order"); - System.out.println("'d' add/remove/change a dish"); - System.out.println("'q' to exit"); + System.out.println("\t Options (choose one): "); + System.out.println("\t 'a' remove all expiring"); + System.out.println("\t 'b' add/remove/use an ingredient"); + System.out.println("\t 'c' place/remove/change an order"); + System.out.println("\t 'd' add/remove/change a dish"); + System.out.println("\t 't' view today's todo list"); + System.out.println("\t 'q' to exit"); } public void showUsed(Ingredient ingredient) { @@ -83,23 +140,55 @@ public void show(String message) { public void showIngredientTask() { showIngredientTemplate(); - System.out.println("type 'back' to go back to the main menu"); - System.out.println("type 'show' to see all ingredients currently in the fridge"); - System.out.println("type 'template' to see the format of the commands"); - } -public void showIngredientTemplate(){ - System.out.println("Continue by adding, removing or using an ingredient \nTemplate: "); - showLine(); - System.out.println("add "); - System.out.println("remove "); - System.out.println("use *always use most recently expiring ingredients first, to prevent food waste!*"); - showLine(); -} + System.out.println("\t type 'back' to go back to the main menu"); + System.out.println("\t type 'show' to see all ingredients currently in the fridge"); + System.out.println("\t type 'template' to see the format of the commands"); + } + + public void showIngredientTemplate(){ + System.out.println("\t Continue by adding, removing or using an ingredient \n\t Template: "); + showLine(); + System.out.println("\t add "); + System.out.println("\t remove "); + System.out.println("\t use *always use most recently expiring ingredients first, to prevent food waste!*"); + showLine(); + } + + public void showDishTemplate() { + dishDrawing(); + showLine(); + System.out.println("\t Continue by adding, removing, listing, adding ingredient and initializing \n\t Template: "); + showLine(); + System.out.println("\t add "); + System.out.println("\t remove "); + System.out.println("\t list"); + System.out.println("\t ingredient "); + System.out.println("\t initialize (REMOVES all entries in the list)"); + System.out.println("\t back, return to main menu"); + System.out.println("\t template"); + showLine(); + } + + public void showOrderTemplate() { + showLine(); + System.out.println("\t Continue by adding, removing, altering, listing order and initializing order list. \n\t Command Template: "); + showLine(); + System.out.println("\t init"); + System.out.println("\t add [-d ORDER_DATE-(dd/mm/yyyy)] -n DISH1_NAME[*DISH_AMOUNT], DISH2_NAME[*DISH_AMOUNT]"); + System.out.println("\t alter ORDER_INDEX ORDER_DATE-(dd/mm/yyyy)"); + System.out.println("\t remove ORDER_INDEX"); + System.out.println("\t done ORDER_INDEX"); + System.out.println("\t list [-l LIST_TYPE-(option: all (default) | undone | today | undoneToday)]"); + System.out.println("\t list -n DISH_NAME *** Find the dishes in today's undone orders ***"); + System.out.println("\t list -d ORDER_DATE-(dd/mm/yyyy) [-l LIST_TYPE-(option: all (default) | undone)]"); + showLine(); + } + public void showIngredientsInFridge(IngredientsList ingredientsList) { if (ingredientsList.isEmpty()) - System.out.println("The fridge is empty, better go buy some ingredients! "); + System.out.println("\t The fridge is empty, better go buy some ingredients! "); else { - System.out.println("Here is a list of all the ingredients in your fridge: "); + System.out.println("\t Here is a list of all the ingredients in your fridge: "); int i = 1; for (Ingredient ingredient : ingredientsList.sortByExpiryDate().getAllEntries()) { System.out.println(i + ": " + ingredient); @@ -136,22 +225,21 @@ public void showTask(String task) { /** * Show that this task is marked. * - * @param doneTask The task that is marked as done + * @param doneOrder The description of the order that is marked as done */ - public void showMarkDone(String doneTask) { - System.out.println("\t Nice! I've marked this task as done:"); - System.out.println("\t " + doneTask); + public void showMarkDoneOrder(String doneOrder) { + System.out.println("\t Nice! I've marked this order as done:"); + System.out.println("\t " + doneOrder); } /** - * Show the task that has been snoozed. + * Show that this task is marked. * - * @param date the date - * @param changedTask the task that has been changed + * @param task The description of the task that is marked as done */ - public void showChangedDate(String date, String changedTask) { - System.out.println("\t Nice! I've snoozed this task as until " + date + ":"); - System.out.println("\t " + changedTask); + public void showMarkDone(String task) { + System.out.println("\t Nice! I've marked this task as done:"); + System.out.println("\t " + task); } /** @@ -210,12 +298,12 @@ public void showAddCommand(String command, int size) { /** * Shows that a order has been added. * - * @param command ay - * @param size ya + * @param description information of the order be added + * @param size current size of the whole order list */ - public void showAddOrder(String command, int size) { + public void showAddOrder(String description, int size) { System.out.println("\t Got it. I've added this order: "); - System.out.println("\t " + command); + System.out.println("\t " + description); showOrderListSize(size); } @@ -225,8 +313,8 @@ public void showAddOrder(String command, int size) { * @param removed the task * @param size size of list */ - public void showRemovedTask(String removed, int size) { - System.out.println("\t Noted. I've removed this task:"); + public void showRemovedIngredient(String removed, int size) { + System.out.println("\t Noted. I've removed this ingredient:"); System.out.println("\t " + removed); showSize(size); } @@ -243,9 +331,16 @@ public void showRemovedOrder(String removed, int size) { showOrderListSize(size); } - public void showAddedDishes(String dish, int Nb) { + public void showAddedDishes(String dish) { + showLine(); System.out.println("\t you have added the following dish: "); - System.out.println("\t " + dish + " \tamount: " + Nb); + System.out.println("\t " + dish); + showLine(); + } + + public void showAddedIngredient(String ingredient) { + System.out.println("\t you have added the following ingredient: "); + System.out.println("\t " + ingredient); } public void showDishes(String Dish, int Nb) { @@ -253,7 +348,25 @@ public void showDishes(String Dish, int Nb) { } public void showDeletedDIsh(String dish) { + showLine(); System.out.println("\t The following dish have been removed:"); System.out.println("\t " + dish); + showLine(); + } + + public void showIngredients(Ingredient ingredient, Dish dish) { + showLine(); + System.out.println("\t ingredient: " + ingredient.getName() + + "\n\t added to: " + dish.getDishname()); + showLine(); + } + + /** + * Every time this method is executed, it clears the console screen. + * @throws IOException + * @throws InterruptedException + */ + public void clearScreen() throws IOException, InterruptedException { + new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); } } diff --git a/src/main/out/production/main/META-INF/main.kotlin_module b/src/main/out/production/main/META-INF/main.kotlin_module new file mode 100644 index 00000000..2983af70 Binary files /dev/null and b/src/main/out/production/main/META-INF/main.kotlin_module differ diff --git a/src/main/out/production/main/duke/fridge/diagram.uml b/src/main/out/production/main/duke/fridge/diagram.uml new file mode 100644 index 00000000..8a42c9e6 --- /dev/null +++ b/src/main/out/production/main/duke/fridge/diagram.uml @@ -0,0 +1,173 @@ + + + JAVA + + + duke.command.ingredientCommand.Snooze + duke.exception.DukeException + duke.command.ingredientCommand.ListCommand + duke.command.FindIngredientCommand + duke.ingredient.Ingredient + duke.parser.Parser + duke.command.dishesCommand.AddDishCommand + duke.command.ingredientCommand.ViewCommand + duke.command.ingredientCommand.RemindCommand + duke.Duke + duke.command.ingredientCommand.AddCommand + duke.dish.DishList + duke.ingredient.IngredientsList + duke.command.Cmd + duke.fridge.Fridge + duke.storage.TaskStorage + duke.order.Order + duke.storage.Printable + duke.order.OrderList + duke.dish.Dish + duke.command.ingredientCommand.ExitCommand + duke.storage.FridgeStorage + duke.command.dishesCommand.ListDishCommand + duke.command.ingredientCommand.FindToday + duke.command.ingredientCommand.DeleteCommand + duke.command.dishesCommand.ResetDishCommand + duke.list.GenericList + duke.command.ingredientCommand.DoneCommand + duke.parser.Convert + duke.command.dishesCommand.DeleteDishCommand + duke.storage.Storage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fields + Constructors + Methods + Properties + Inner Classes + + All + private + +