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
+
+