Skip to content

Commit

Permalink
Merge pull request nusCS2113-AY1920S1#14 from 9hafidz6/master
Browse files Browse the repository at this point in the history
added recipeCommand package
  • Loading branch information
9hafidz6 authored Oct 17, 2019
2 parents 19ff140 + 9bdd686 commit f189a12
Show file tree
Hide file tree
Showing 24 changed files with 398 additions and 120 deletions.
8 changes: 5 additions & 3 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import duke.command.Command;
import duke.exception.DukeException;
import duke.parser.Parser;
import duke.recipebook.dishlist;
import duke.recipeCommand.RecipeCommand;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;
Expand All @@ -16,14 +17,14 @@ public class Duke {
private Storage storage;
private TaskList tasks;
private Ui ui;
private dishlist dish;
private DishList dish;

/**
* The constructor method for Duke.
* @param filePath used to specify the location of the file in the hard disc.
*/
public Duke(String filePath) {
dish = new dishlist();
dish = new DishList();
ui = new Ui();
storage = new Storage(filePath);
try {
Expand All @@ -45,6 +46,7 @@ public void run() {
String fullCommand = ui.readCommand();
ui.showLine();
Command c = Parser.parse(fullCommand, tasks.size());
// RecipeCommand c = Parser.Parse(fullCommand); //execute the recipeCommands, add dishes etc
c.execute(dish, tasks, ui, storage);
isExit = c.isExit();
} catch (DukeException e) {
Expand Down
28 changes: 12 additions & 16 deletions src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package duke.command;

import duke.exception.DukeException;
import duke.recipebook.dishes;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.recipebook.Dishes;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;
Expand All @@ -16,7 +17,6 @@
public class AddCommand extends Command {

private Task task;
private dishes dish;

/**
* The constructor method for AddCommand.
Expand All @@ -27,28 +27,24 @@ public AddCommand(Task task) {
this.task = task;
}

public AddCommand(dishes dish) {
this.dish = dish;
}

/**
* Public method used to add the task in the taskList, and write it on the hard disc.
*
*
* @param dish1
* @param taskList the {@link TaskList} 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(dishlist dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
taskList.addTask(task);
dish1.addDish(dish); // add dish into list found in dishes class
System.out.println("\t dish added: " + dish.toString() + "\n\t amount :" + dish.getAmount());
// ui.showAddCommand(task.toString(), taskList.size());
// try {
// storage.addCommandInFile(task.printInFile());
// } catch (IOException e) {
// throw new DukeException("Error while adding the command to the duke.txt file");
// }
ui.showAddCommand(task.toString(), taskList.size());
try {
storage.addCommandInFile(task.printInFile());
} catch (IOException e) {
throw new DukeException("Error while adding the command to the duke.txt file");
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package duke.command;

import duke.exception.DukeException;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;
Expand All @@ -11,7 +12,7 @@
*/
public abstract class Command {

public abstract void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException;
public abstract void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException;

/**
* Returns the boolean indicating that it is( not) an {@link ExitCommand}.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package duke.command;

import duke.exception.DukeException;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;
Expand All @@ -24,7 +25,7 @@ public DeleteCommand(int taskNb) {
}

@Override
public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
if (taskNb < taskList.size() && taskNb >= 0) {
Task removed = taskList.removeTask(taskNb);
List<String> fileContent = null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package duke.command;

import duke.exception.DukeException;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;
Expand All @@ -18,7 +18,7 @@ public DoneCommand(int taskNb) {
}

@Override
public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
if (taskNb < taskList.size() && taskNb >= 0) {
taskList.markTaskDone(taskNb);
ui.showMarkDone(taskList.getTask(taskNb).toString());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package duke.command;

import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;
Expand All @@ -16,7 +16,7 @@ public boolean isExit() {
}

@Override
public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) {
System.out.println("\t Bye. Hope to see you again soon!");
}
}
4 changes: 2 additions & 2 deletions src/main/java/duke/command/FindToday.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package duke.command;

import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;
Expand All @@ -21,7 +21,7 @@ public boolean isExit() {
return false;
}

public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) {
int i = 1;
StringBuilder sb = new StringBuilder();

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/duke/command/InitCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package duke.command;

import duke.exception.DukeException;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;
import duke.recipebook.dishes;

public class InitCommand extends Command {

Expand All @@ -16,7 +15,7 @@ public InitCommand() {
}

@Override
public void execute(dishlist dish, TaskList taskList, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dish, TaskList taskList, Ui ui, Storage storage) throws DukeException {
//something
}
}
4 changes: 2 additions & 2 deletions src/main/java/duke/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package duke.command;

import duke.exception.DukeException;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;
Expand All @@ -12,7 +12,7 @@
public class ListCommand extends Command {

@Override
public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
if (taskList.size() == 0) {
throw new DukeException("No tasks yet!");
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/RemindCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package duke.command;

import duke.exception.DukeException;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;
Expand All @@ -21,7 +21,7 @@ public RemindCommand() {
}

@Override
public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
int num = 1;
LocalDate date = LocalDate.now();
LocalDate date1 = date.plusDays(5);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/Snooze.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import duke.exception.DukeException;
import duke.parser.Convert;
import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;
Expand Down Expand Up @@ -32,7 +32,7 @@ public Snooze(int taskNb, String until) {
}

@Override
public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {
if (taskNb < taskList.size() && taskNb >= 0) {
if (taskList.getTask(taskNb).isDone()) {
throw new DukeException("Seems like you've already finished that task, no need to snooze it now");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/command/ViewCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package duke.command;

import duke.recipebook.dishlist;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.Task;
import duke.task.TaskList;
Expand All @@ -21,7 +21,7 @@ public ViewCommand(Date toView) {
}

@Override
public void execute(dishlist dish1, TaskList taskList, Ui ui, Storage storage) {
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) {
StringBuilder sb = new StringBuilder();
int i = 1;
try {
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import duke.Duke;
import duke.command.*;
import duke.command.AddCommand;
import duke.command.Command;
import duke.command.DoneCommand;
import duke.command.ExitCommand;
import duke.command.FindIngredientCommand;
import duke.command.RemindCommand;
import duke.command.ViewCommand;
import duke.exception.DukeException;
import duke.orderCommand.*;
import duke.recipebook.dishes;
import duke.recipeCommand.*;
import duke.recipeCommand.InitCommand;
import duke.recipebook.Dishes;
import duke.task.Deadline;
import duke.task.DoWithinPeriodTasks;
import duke.task.Event;
Expand Down Expand Up @@ -38,7 +41,7 @@ public class Parser {
*/
public static Command parse(String fullCommand, int size) throws DukeException {
//splitted contains the keyword and the rest (description or task number)
String[] splitted = fullCommand.split(" ", 3);
String[] splitted = fullCommand.split(" ", 2);
//switching on the keyword
switch (splitted[0]) {
case "list":
Expand Down Expand Up @@ -82,9 +85,29 @@ public static Command parse(String fullCommand, int size) throws DukeException {
String[] getPart = splitAndCheck(splitted[1], " /from ");
String[] part = splitAndCheck(getPart[1], " /to ");
return new AddCommand(new DoWithinPeriodTasks(getPart[0], part[0], part[1]));
case "add":
int amount = Integer.parseInt(splitted[2]);
return new AddCommand(new dishes(splitted[1], amount));
default:
throw new DukeException("I'm sorry, but I don't know what that means :-(");
}
}

public static RecipeCommand Parse(String fullCommaand) throws DukeException {
String[] splitted = fullCommaand.split(" ", 2);
switch (splitted[0]) {
case "dishadd":
String[] getnum = splitAndCheck(splitted[1], " /num ");
int amount = Integer.parseInt(getnum[1]);
return new AddDishCommand(new Dishes(getnum[0]), amount);
case "listdish":
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 AddIngredientCommand(getIng[0], listNum);
case "init" :
return new InitCommand();
default:
throw new DukeException("I'm sorry, but I don't know what that means :-(");
}
Expand Down Expand Up @@ -115,6 +138,8 @@ public static OrderCommand parse(String fullCommand) throws DukeException {
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.
* @throws DukeException when array is not of size 2.
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/duke/recipeCommand/AddDishCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package duke.recipeCommand;

import duke.exception.DukeException;
import duke.recipebook.Dishes;
import duke.recipebook.DishList;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class AddDishCommand extends RecipeCommand {

private Dishes dish;
private int amount;
private int Nb;

public AddDishCommand(Dishes dish, int amount) {
this.dish = dish;
this.amount = amount;
}

@Override
public void execute(DishList dish1, TaskList taskList, Ui ui, Storage storage) throws DukeException {

try {
dish1.addDish(dish); // add dish into list found in dishes class

for( int i = 1; i < DishList.getSize(); i++) {
if(DishList.getDish(i).getDishname().equals(dish.toString())){
Nb = i;
break;
}
}
dish1.getDish(Nb).setNumberOfOrders(amount);
ui.showAddedDishes(dish.toString(), DishList.getDish(Nb).getTotalNumberOfOrders());
} catch (Exception e) {
throw new DukeException("unable to add dish");
}
}
}
Loading

0 comments on commit f189a12

Please sign in to comment.