From 72ae4595061ee9646f53bd8683736f41522f4154 Mon Sep 17 00:00:00 2001
From: Dexter <35828587+DextheChik3n@users.noreply.github.com>
Date: Wed, 27 Sep 2023 16:22:10 +0800
Subject: [PATCH 001/870] Add Github Pages theme
---
docs/_config.yml | 1 +
1 file changed, 1 insertion(+)
create mode 100644 docs/_config.yml
diff --git a/docs/_config.yml b/docs/_config.yml
new file mode 100644
index 0000000000..a25eb13c93
--- /dev/null
+++ b/docs/_config.yml
@@ -0,0 +1 @@
+theme: minima
From 094363dc81635ad0658ac71e4eb02ca05a61c993 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Thu, 5 Oct 2023 17:47:54 +0800
Subject: [PATCH 002/870] Edit about us with updated information.
---
docs/AboutUs.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 0f072953ea..60c846c109 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -1,9 +1,9 @@
# About us
-Display | Name | Github Profile | Portfolio
---------|:----:|:--------------:|:---------:
-![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+Display | Name | Github Profile | Portfolio
+--------|:--------:|:--------------:|:---------:
+![](https://via.placeholder.com/100.png?text=Photo) | Naychi | [Github](https://github.com/NaychiMin/tp) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
From 21a60988c0892050292fffd82c8fb54d749500d8 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Thu, 5 Oct 2023 17:48:06 +0800
Subject: [PATCH 003/870] Add information in AboutUs.md
---
docs/AboutUs.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 0f072953ea..c6d11ebc79 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -1,9 +1,9 @@
# About us
-Display | Name | Github Profile | Portfolio
---------|:----:|:--------------:|:---------:
-![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+Display | Name | Github Profile | Portfolio
+--------|:-----------:|:--------------:|:---------:
+![](https://via.placeholder.com/100.png?text=Photo) | Dexter Hoon | [Github](https://github.com/DextheChik3n) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
From ce55b55eeedfddf78b8dcd41a589ab3097fc943f Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Thu, 5 Oct 2023 17:48:31 +0800
Subject: [PATCH 004/870] Update AboutUs.md with Ziyi's name and github
---
docs/AboutUs.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 0f072953ea..d552bd0091 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -1,9 +1,9 @@
# About us
-Display | Name | Github Profile | Portfolio
---------|:----:|:--------------:|:---------:
-![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+Display | Name | Github Profile | Portfolio
+--------|:--------:|:------------------------------------:|:---------:
+![](https://via.placeholder.com/100.png?text=Photo) | Zi Yi | [Github](https://github.com/ziyi105) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
From 88288a4ee312a4a3906c0c7f8ecad9003abaf8fa Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Thu, 5 Oct 2023 17:48:40 +0800
Subject: [PATCH 005/870] Update AboutUs.md
---
docs/AboutUs.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 0f072953ea..ecdda9d867 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -1,9 +1,9 @@
# About us
-Display | Name | Github Profile | Portfolio
---------|:----:|:--------------:|:---------:
-![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+Display | Name | Github Profile | Portfolio
+--------|:--------:|:----------------------------------------:|:---------:
+![](https://via.placeholder.com/100.png?text=Photo) | Shanice | [Github](https://github.com/ShaniceTang) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
From 070155ed53e9e987a79208ac10c5a7942c4cf353 Mon Sep 17 00:00:00 2001
From: ZH
Date: Thu, 5 Oct 2023 18:04:48 +0800
Subject: [PATCH 006/870] Update AboutUs.md
---
docs/AboutUs.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 0f072953ea..f64f4c5b51 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -1,9 +1,9 @@
# About us
-Display | Name | Github Profile | Portfolio
---------|:----:|:--------------:|:---------:
-![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+Display | Name | Github Profile | Portfolio
+--------|:---------------:|:-------------------------------------:|:---------:
+![](https://via.placeholder.com/100.png?text=Photo) | Chua Zhong Heng | [Github](https://github.com/Cazh1/tp) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
+![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
From db3be0d4dbc95092f2a772ee485cf24139f4a960 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Thu, 5 Oct 2023 18:05:55 +0800
Subject: [PATCH 007/870] Update Ziyi's photo on AboutUs.md
---
docs/AboutUs.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/AboutUs.md b/docs/AboutUs.md
index 76f0e27dda..a62b6988b7 100644
--- a/docs/AboutUs.md
+++ b/docs/AboutUs.md
@@ -4,7 +4,7 @@ Display | Name | Github Profile | Portfolio
--------|:--------:|:----------------------------------------:|:---------:
![](https://via.placeholder.com/100.png?text=Photo) | Shanice | [Github](https://github.com/ShaniceTang) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Naychi | [Github](https://github.com/NaychiMin/tp) | [Portfolio](docs/team/johndoe.md)
-![](https://via.placeholder.com/100.png?text=Photo) | Zi Yi | [Github](https://github.com/ziyi105) | [Portfolio](docs/team/johndoe.md)
+![](https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.scmp.com%2Fweek-asia%2Fpolitics%2Farticle%2F3095228%2Fmalaysia-najibs-cheesy-super-ring-jibe-comes-back-bite-him-after&psig=AOvVaw2ohFjBBhoZxtARfOKEnTXE&ust=1696586245977000&source=images&cd=vfe&opi=89978449&ved=0CBEQjRxqFwoTCJiboLbS3oEDFQAAAAAdAAAAABAE) | Zi Yi | [Github](https://github.com/ziyi105) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Dexter Hoon | [Github](https://github.com/DextheChik3n) | [Portfolio](docs/team/johndoe.md)
![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md)
From a58bed14f14de4d92994e46cc136783aba7fd4c3 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sat, 14 Oct 2023 20:17:01 +0800
Subject: [PATCH 008/870] Add Parser.java
fixes #8
---
src/main/java/Parser/Parser.java | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 src/main/java/Parser/Parser.java
diff --git a/src/main/java/Parser/Parser.java b/src/main/java/Parser/Parser.java
new file mode 100644
index 0000000000..33718c4606
--- /dev/null
+++ b/src/main/java/Parser/Parser.java
@@ -0,0 +1,9 @@
+package Parser;
+
+/**
+ * Parse everything received from the users on terminal
+ * into a format that can be interpreted by other core classes
+ */
+public class Parser {
+
+}
From 5ddffe229dba287cf4773bad97938c3b6659e9ef Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sat, 14 Oct 2023 21:20:44 +0800
Subject: [PATCH 009/870] Parser.java: move from package Parser to
seedu.duke.parser
---
src/main/java/{Parser => seedu/duke/parser}/Parser.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename src/main/java/{Parser => seedu/duke/parser}/Parser.java (85%)
diff --git a/src/main/java/Parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
similarity index 85%
rename from src/main/java/Parser/Parser.java
rename to src/main/java/seedu/duke/parser/Parser.java
index 33718c4606..e23fe0ca92 100644
--- a/src/main/java/Parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -1,4 +1,4 @@
-package Parser;
+package seedu.duke.parser;
/**
* Parse everything received from the users on terminal
From b806594dfa85c2c71007f457c46139694b196274 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sat, 14 Oct 2023 21:21:21 +0800
Subject: [PATCH 010/870] Add ParserTest.java
fixes #12
---
src/test/java/seedu/duke/parser/ParserTest.java | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 src/test/java/seedu/duke/parser/ParserTest.java
diff --git a/src/test/java/seedu/duke/parser/ParserTest.java b/src/test/java/seedu/duke/parser/ParserTest.java
new file mode 100644
index 0000000000..2dcf3f6449
--- /dev/null
+++ b/src/test/java/seedu/duke/parser/ParserTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.parser;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ParserTest {
+
+}
\ No newline at end of file
From 74d345ea8d7fd35e7906b35ae7c5dea5124d0f2f Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sat, 14 Oct 2023 22:00:31 +0800
Subject: [PATCH 011/870] ParserTest.java: remove wild card import
---
src/test/java/seedu/duke/parser/ParserTest.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/test/java/seedu/duke/parser/ParserTest.java b/src/test/java/seedu/duke/parser/ParserTest.java
index 2dcf3f6449..9b5a90f96d 100644
--- a/src/test/java/seedu/duke/parser/ParserTest.java
+++ b/src/test/java/seedu/duke/parser/ParserTest.java
@@ -1,7 +1,5 @@
package seedu.duke.parser;
-import static org.junit.jupiter.api.Assertions.*;
-
class ParserTest {
}
\ No newline at end of file
From 72f47e36ee6fc50c291c3ba56995c48ca4d7adec Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 15 Oct 2023 00:18:22 +0800
Subject: [PATCH 012/870] ParserTest.java: add a new line at the end of the
file
---
src/test/java/seedu/duke/parser/ParserTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/seedu/duke/parser/ParserTest.java b/src/test/java/seedu/duke/parser/ParserTest.java
index 9b5a90f96d..4bb8562b64 100644
--- a/src/test/java/seedu/duke/parser/ParserTest.java
+++ b/src/test/java/seedu/duke/parser/ParserTest.java
@@ -2,4 +2,4 @@
class ParserTest {
-}
\ No newline at end of file
+}
From ce21b499b97b8604e902d81c2ffc5d2e5e3dbda1 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 15 Oct 2023 00:50:17 +0800
Subject: [PATCH 013/870] Add Menu.java, Dish.java, Ingredient.java and their
test classes
---
src/main/java/seedu/duke/data/Menu.java | 13 +++++++++++++
src/main/java/seedu/duke/data/dish/Dish.java | 15 +++++++++++++++
.../java/seedu/duke/data/dish/Ingredient.java | 9 +++++++++
src/test/java/seedu/duke/data/MenuTest.java | 7 +++++++
src/test/java/seedu/duke/data/dish/DishTest.java | 7 +++++++
.../java/seedu/duke/data/dish/IngredientTest.java | 7 +++++++
6 files changed, 58 insertions(+)
create mode 100644 src/main/java/seedu/duke/data/Menu.java
create mode 100644 src/main/java/seedu/duke/data/dish/Dish.java
create mode 100644 src/main/java/seedu/duke/data/dish/Ingredient.java
create mode 100644 src/test/java/seedu/duke/data/MenuTest.java
create mode 100644 src/test/java/seedu/duke/data/dish/DishTest.java
create mode 100644 src/test/java/seedu/duke/data/dish/IngredientTest.java
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
new file mode 100644
index 0000000000..f5317a3d44
--- /dev/null
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -0,0 +1,13 @@
+package seedu.duke.data;
+
+import seedu.duke.data.dish.Dish;
+
+import java.util.ArrayList;
+
+public class Menu {
+ private ArrayList menuItems;
+
+ public Menu(ArrayList menuItems) {
+ this.menuItems = menuItems;
+ }
+}
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/duke/data/dish/Dish.java
new file mode 100644
index 0000000000..778786caa8
--- /dev/null
+++ b/src/main/java/seedu/duke/data/dish/Dish.java
@@ -0,0 +1,15 @@
+package seedu.duke.data.dish;
+
+import java.util.ArrayList;
+
+public class Dish {
+ private String name;
+ private ArrayList ingredients;
+ private double price;
+
+ public Dish(String name, ArrayList ingredients, double price) {
+ this.name = name;
+ this.ingredients = ingredients;
+ this.price = price;
+ }
+}
diff --git a/src/main/java/seedu/duke/data/dish/Ingredient.java b/src/main/java/seedu/duke/data/dish/Ingredient.java
new file mode 100644
index 0000000000..11478bc98a
--- /dev/null
+++ b/src/main/java/seedu/duke/data/dish/Ingredient.java
@@ -0,0 +1,9 @@
+package seedu.duke.data.dish;
+
+public class Ingredient {
+ private final String name;
+
+ public Ingredient(String name) {
+ this.name = name;
+ }
+}
diff --git a/src/test/java/seedu/duke/data/MenuTest.java b/src/test/java/seedu/duke/data/MenuTest.java
new file mode 100644
index 0000000000..81e7db5e31
--- /dev/null
+++ b/src/test/java/seedu/duke/data/MenuTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.data;
+
+//import static org.junit.jupiter.api.Assertions.*;
+
+class MenuTest {
+
+}
diff --git a/src/test/java/seedu/duke/data/dish/DishTest.java b/src/test/java/seedu/duke/data/dish/DishTest.java
new file mode 100644
index 0000000000..e315fb3f62
--- /dev/null
+++ b/src/test/java/seedu/duke/data/dish/DishTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.data.dish;
+
+//import static org.junit.jupiter.api.Assertions.*;
+
+class DishTest {
+
+}
diff --git a/src/test/java/seedu/duke/data/dish/IngredientTest.java b/src/test/java/seedu/duke/data/dish/IngredientTest.java
new file mode 100644
index 0000000000..f3b5c160ac
--- /dev/null
+++ b/src/test/java/seedu/duke/data/dish/IngredientTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.data.dish;
+
+//import static org.junit.jupiter.api.Assertions.*;
+
+class IngredientTest {
+
+}
From 6cd980d30ffc7269100b0e144deb704624108ba4 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 15 Oct 2023 00:52:17 +0800
Subject: [PATCH 014/870] Add Menu.java
fixes 31
---
src/main/java/seedu/duke/data/Menu.java | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
index f5317a3d44..e69de29bb2 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -1,13 +0,0 @@
-package seedu.duke.data;
-
-import seedu.duke.data.dish.Dish;
-
-import java.util.ArrayList;
-
-public class Menu {
- private ArrayList menuItems;
-
- public Menu(ArrayList menuItems) {
- this.menuItems = menuItems;
- }
-}
From 9de4ee60d69353f1d1e32b5a60b5b27991d8219c Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 15 Oct 2023 00:53:11 +0800
Subject: [PATCH 015/870] Revert "Add Menu.java"
This reverts commit 6cd980d30ffc7269100b0e144deb704624108ba4.
---
src/main/java/seedu/duke/data/Menu.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
index e69de29bb2..f5317a3d44 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -0,0 +1,13 @@
+package seedu.duke.data;
+
+import seedu.duke.data.dish.Dish;
+
+import java.util.ArrayList;
+
+public class Menu {
+ private ArrayList menuItems;
+
+ public Menu(ArrayList menuItems) {
+ this.menuItems = menuItems;
+ }
+}
From 79afe5da305b841bf11d7be35b464cbfc2ad8134 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 15 Oct 2023 15:58:59 +0800
Subject: [PATCH 016/870] Dish.java: change price type double to float
---
src/main/java/seedu/duke/data/dish/Dish.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/duke/data/dish/Dish.java
index 778786caa8..07f883c7ed 100644
--- a/src/main/java/seedu/duke/data/dish/Dish.java
+++ b/src/main/java/seedu/duke/data/dish/Dish.java
@@ -5,9 +5,9 @@
public class Dish {
private String name;
private ArrayList ingredients;
- private double price;
+ private float price;
- public Dish(String name, ArrayList ingredients, double price) {
+ public Dish(String name, ArrayList ingredients, float price) {
this.name = name;
this.ingredients = ingredients;
this.price = price;
From e5534107d88a9f49f4eaa864f24622948c9dc773 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 15 Oct 2023 17:00:06 +0800
Subject: [PATCH 017/870] ParserTest.java: add javadoc to the class
---
src/test/java/seedu/duke/parser/ParserTest.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/test/java/seedu/duke/parser/ParserTest.java b/src/test/java/seedu/duke/parser/ParserTest.java
index 4bb8562b64..f9108f5a6e 100644
--- a/src/test/java/seedu/duke/parser/ParserTest.java
+++ b/src/test/java/seedu/duke/parser/ParserTest.java
@@ -1,5 +1,8 @@
package seedu.duke.parser;
+/**
+ * Junit test for Parser.java
+ */
class ParserTest {
}
From 78321f89bd358320aec6190b2e1f57bceec9b61b Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Sun, 15 Oct 2023 18:01:49 +0800
Subject: [PATCH 018/870] Add Ui class for user input handling and UserOutput
enum for user messages. Fixes #9
---
src/main/java/seedu/duke/ui/Ui.java | 39 +++++++++++++++++++++
src/main/java/seedu/duke/ui/UserOutput.java | 15 ++++++++
2 files changed, 54 insertions(+)
create mode 100644 src/main/java/seedu/duke/ui/Ui.java
create mode 100644 src/main/java/seedu/duke/ui/UserOutput.java
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
new file mode 100644
index 0000000000..62dfa3e376
--- /dev/null
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -0,0 +1,39 @@
+package seedu.duke.ui;
+
+import java.util.Scanner;
+
+public class Ui {
+ private final Scanner scanner;
+
+ /**
+ * Constructs a UI instance with a Scanner for user input.
+ */
+ public Ui() {
+ scanner = new Scanner(System.in);
+ }
+
+ public String receiveUserInput() {
+ return scanner.nextLine();
+ }
+
+ public void showWelcome() {
+ System.out.println(UserOutput.WELCOME_MESSAGE.message);
+ }
+
+ public void showGoodbye() {
+ System.out.println(UserOutput.GOODBYE_MESSAGE.message);
+ }
+
+ /**
+ * Displays an error message.
+ * We will probably use the function when we perform
+ * error handling to display the messages to the user.
+ * Though it may not be used in V0.1, I think there's
+ * no harm adding it in for now! :)
+ *
+ * @param errorMessage The error message to display.
+ */
+ public void showError(String errorMessage) {
+ System.out.println(errorMessage);
+ }
+}
diff --git a/src/main/java/seedu/duke/ui/UserOutput.java b/src/main/java/seedu/duke/ui/UserOutput.java
new file mode 100644
index 0000000000..bf1ef84746
--- /dev/null
+++ b/src/main/java/seedu/duke/ui/UserOutput.java
@@ -0,0 +1,15 @@
+package seedu.duke.ui;
+
+/**
+ * Enumerates messages to be displayed to users.
+ */
+public enum UserOutput {
+ WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
+ GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!")
+ ;
+
+ public final String message;
+ UserOutput(String message) {
+ this.message = message;
+ }
+}
From dadae0261aa4778ac64d68cbc66ec345da97f599 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 15 Oct 2023 21:17:30 +0800
Subject: [PATCH 019/870] Fixes #27
Create UiTest JUnit Class
---
src/test/java/seedu/duke/UiTest.java | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 src/test/java/seedu/duke/UiTest.java
diff --git a/src/test/java/seedu/duke/UiTest.java b/src/test/java/seedu/duke/UiTest.java
new file mode 100644
index 0000000000..044150d19e
--- /dev/null
+++ b/src/test/java/seedu/duke/UiTest.java
@@ -0,0 +1,4 @@
+package seedu.duke;
+
+public class UiTest {
+}
From ba46ad20ecedd9d0cb49290bd75ba7df3e989b11 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 15 Oct 2023 21:28:30 +0800
Subject: [PATCH 020/870] Add javadoc to UiTest class
---
src/test/java/seedu/duke/UiTest.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/test/java/seedu/duke/UiTest.java b/src/test/java/seedu/duke/UiTest.java
index 044150d19e..dccca8009f 100644
--- a/src/test/java/seedu/duke/UiTest.java
+++ b/src/test/java/seedu/duke/UiTest.java
@@ -1,4 +1,8 @@
package seedu.duke;
+
+/**
+ * Junit test for Ui.java
+ */
public class UiTest {
}
From 47e208e3c20a79c10f0f4c9fe082b7db52170725 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Sun, 15 Oct 2023 22:50:15 +0800
Subject: [PATCH 021/870] Remove showError() function from Ui class.
---
src/main/java/seedu/duke/ui/Ui.java | 13 -------------
src/main/java/seedu/duke/ui/UserOutput.java | 3 +--
2 files changed, 1 insertion(+), 15 deletions(-)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 62dfa3e376..298654281f 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -23,17 +23,4 @@ public void showWelcome() {
public void showGoodbye() {
System.out.println(UserOutput.GOODBYE_MESSAGE.message);
}
-
- /**
- * Displays an error message.
- * We will probably use the function when we perform
- * error handling to display the messages to the user.
- * Though it may not be used in V0.1, I think there's
- * no harm adding it in for now! :)
- *
- * @param errorMessage The error message to display.
- */
- public void showError(String errorMessage) {
- System.out.println(errorMessage);
- }
}
diff --git a/src/main/java/seedu/duke/ui/UserOutput.java b/src/main/java/seedu/duke/ui/UserOutput.java
index bf1ef84746..19c248a4de 100644
--- a/src/main/java/seedu/duke/ui/UserOutput.java
+++ b/src/main/java/seedu/duke/ui/UserOutput.java
@@ -5,8 +5,7 @@
*/
public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
- GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!")
- ;
+ GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!");
public final String message;
UserOutput(String message) {
From 7c37a72bf95a8e73203623e2f7bba0d31d980da2 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 12:00:16 +0800
Subject: [PATCH 022/870] Add Command class
Fixes #10
---
src/main/java/seedu/duke/command/AddCommand.java | 11 +++++++++++
src/main/java/seedu/duke/command/Command.java | 13 +++++++++++++
src/main/java/seedu/duke/command/DeleteCommand.java | 12 ++++++++++++
src/main/java/seedu/duke/command/ListCommand.java | 11 +++++++++++
.../java/seedu/duke/command/AddCommandTest.java | 7 +++++++
src/test/java/seedu/duke/command/CommandTest.java | 7 +++++++
.../java/seedu/duke/command/DeleteCommandTest.java | 7 +++++++
.../java/seedu/duke/command/ListCommandTest.java | 7 +++++++
8 files changed, 75 insertions(+)
create mode 100644 src/main/java/seedu/duke/command/AddCommand.java
create mode 100644 src/main/java/seedu/duke/command/Command.java
create mode 100644 src/main/java/seedu/duke/command/DeleteCommand.java
create mode 100644 src/main/java/seedu/duke/command/ListCommand.java
create mode 100644 src/test/java/seedu/duke/command/AddCommandTest.java
create mode 100644 src/test/java/seedu/duke/command/CommandTest.java
create mode 100644 src/test/java/seedu/duke/command/DeleteCommandTest.java
create mode 100644 src/test/java/seedu/duke/command/ListCommandTest.java
diff --git a/src/main/java/seedu/duke/command/AddCommand.java b/src/main/java/seedu/duke/command/AddCommand.java
new file mode 100644
index 0000000000..03b8554f44
--- /dev/null
+++ b/src/main/java/seedu/duke/command/AddCommand.java
@@ -0,0 +1,11 @@
+package seedu.duke.command;
+
+/**
+ * Adds a menu item to the user
+ */
+public class AddCommand extends Command{
+ @Override
+ public void execute() {
+
+ };
+}
diff --git a/src/main/java/seedu/duke/command/Command.java b/src/main/java/seedu/duke/command/Command.java
new file mode 100644
index 0000000000..b2115a9f93
--- /dev/null
+++ b/src/main/java/seedu/duke/command/Command.java
@@ -0,0 +1,13 @@
+package seedu.duke.command;
+
+/**
+ * Represents an executable command.
+ */
+public class Command {
+ /**
+ * Executes the command and returns the result.
+ */
+ public void execute() {
+ throw new UnsupportedOperationException("This method is to be implemented by child classes");
+ };
+}
diff --git a/src/main/java/seedu/duke/command/DeleteCommand.java b/src/main/java/seedu/duke/command/DeleteCommand.java
new file mode 100644
index 0000000000..f11d0492ad
--- /dev/null
+++ b/src/main/java/seedu/duke/command/DeleteCommand.java
@@ -0,0 +1,12 @@
+package seedu.duke.command;
+
+/**
+ * Deletes a task identified using it's last displayed index from the task list.
+ */
+public class DeleteCommand extends Command {
+
+ @Override
+ public void execute() {
+
+ };
+}
diff --git a/src/main/java/seedu/duke/command/ListCommand.java b/src/main/java/seedu/duke/command/ListCommand.java
new file mode 100644
index 0000000000..f6434ba82b
--- /dev/null
+++ b/src/main/java/seedu/duke/command/ListCommand.java
@@ -0,0 +1,11 @@
+package seedu.duke.command;
+
+/**
+ * Lists all tasks in the menu to the user.
+ */
+public class ListCommand extends Command {
+ @Override
+ public void execute() {
+
+ };
+}
diff --git a/src/test/java/seedu/duke/command/AddCommandTest.java b/src/test/java/seedu/duke/command/AddCommandTest.java
new file mode 100644
index 0000000000..8f3c90e8c5
--- /dev/null
+++ b/src/test/java/seedu/duke/command/AddCommandTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.command;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class AddCommandTest {
+
+}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/CommandTest.java b/src/test/java/seedu/duke/command/CommandTest.java
new file mode 100644
index 0000000000..57c9cbb950
--- /dev/null
+++ b/src/test/java/seedu/duke/command/CommandTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.command;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CommandTest {
+
+}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/DeleteCommandTest.java b/src/test/java/seedu/duke/command/DeleteCommandTest.java
new file mode 100644
index 0000000000..db8409d2b5
--- /dev/null
+++ b/src/test/java/seedu/duke/command/DeleteCommandTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.command;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class DeleteCommandTest {
+
+}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/ListCommandTest.java b/src/test/java/seedu/duke/command/ListCommandTest.java
new file mode 100644
index 0000000000..df416b34d0
--- /dev/null
+++ b/src/test/java/seedu/duke/command/ListCommandTest.java
@@ -0,0 +1,7 @@
+package seedu.duke.command;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ListCommandTest {
+
+}
\ No newline at end of file
From 41a9cdcf458fc3a5c3263d6a38a86dcd2df4bf24 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 12:04:21 +0800
Subject: [PATCH 023/870] Update DeleteCommand.java documentation
---
src/main/java/seedu/duke/command/DeleteCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/DeleteCommand.java b/src/main/java/seedu/duke/command/DeleteCommand.java
index f11d0492ad..9da07036f7 100644
--- a/src/main/java/seedu/duke/command/DeleteCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteCommand.java
@@ -1,7 +1,7 @@
package seedu.duke.command;
/**
- * Deletes a task identified using it's last displayed index from the task list.
+ * Deletes a menu item identified using it's last displayed index from the menu.
*/
public class DeleteCommand extends Command {
From d97572fd5728f2ca25a88738e0051ea5e7eb8ad0 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 12:36:39 +0800
Subject: [PATCH 024/870] Update class names to be more specific
---
.../{AddCommand.java => AddDishCommand.java} | 2 +-
...eleteCommand.java => DeleteDishCommand.java} | 2 +-
.../seedu/duke/command/IncorrectCommand.java | 17 +++++++++++++++++
.../java/seedu/duke/command/ListCommand.java | 11 -----------
.../duke/command/ListIngredientCommand.java | 11 +++++++++++
.../seedu/duke/command/ListMenuCommand.java | 11 +++++++++++
.../java/seedu/duke/command/AddCommandTest.java | 7 -------
.../seedu/duke/command/AddDishCommandTest.java | 5 +++++
.../java/seedu/duke/command/CommandTest.java | 2 --
.../seedu/duke/command/DeleteCommandTest.java | 7 -------
.../duke/command/DeleteDishCommandTest.java | 5 +++++
.../seedu/duke/command/ListCommandTest.java | 7 -------
.../duke/command/ListIngredientCommandTest.java | 5 +++++
.../seedu/duke/command/ListMenuCommandTest.java | 5 +++++
14 files changed, 61 insertions(+), 36 deletions(-)
rename src/main/java/seedu/duke/command/{AddCommand.java => AddDishCommand.java} (72%)
rename src/main/java/seedu/duke/command/{DeleteCommand.java => DeleteDishCommand.java} (77%)
create mode 100644 src/main/java/seedu/duke/command/IncorrectCommand.java
delete mode 100644 src/main/java/seedu/duke/command/ListCommand.java
create mode 100644 src/main/java/seedu/duke/command/ListIngredientCommand.java
create mode 100644 src/main/java/seedu/duke/command/ListMenuCommand.java
delete mode 100644 src/test/java/seedu/duke/command/AddCommandTest.java
create mode 100644 src/test/java/seedu/duke/command/AddDishCommandTest.java
delete mode 100644 src/test/java/seedu/duke/command/DeleteCommandTest.java
create mode 100644 src/test/java/seedu/duke/command/DeleteDishCommandTest.java
delete mode 100644 src/test/java/seedu/duke/command/ListCommandTest.java
create mode 100644 src/test/java/seedu/duke/command/ListIngredientCommandTest.java
create mode 100644 src/test/java/seedu/duke/command/ListMenuCommandTest.java
diff --git a/src/main/java/seedu/duke/command/AddCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
similarity index 72%
rename from src/main/java/seedu/duke/command/AddCommand.java
rename to src/main/java/seedu/duke/command/AddDishCommand.java
index 03b8554f44..cd956af6f2 100644
--- a/src/main/java/seedu/duke/command/AddCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -3,7 +3,7 @@
/**
* Adds a menu item to the user
*/
-public class AddCommand extends Command{
+public class AddDishCommand extends Command{
@Override
public void execute() {
diff --git a/src/main/java/seedu/duke/command/DeleteCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
similarity index 77%
rename from src/main/java/seedu/duke/command/DeleteCommand.java
rename to src/main/java/seedu/duke/command/DeleteDishCommand.java
index 9da07036f7..5447402c3d 100644
--- a/src/main/java/seedu/duke/command/DeleteCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -3,7 +3,7 @@
/**
* Deletes a menu item identified using it's last displayed index from the menu.
*/
-public class DeleteCommand extends Command {
+public class DeleteDishCommand extends Command {
@Override
public void execute() {
diff --git a/src/main/java/seedu/duke/command/IncorrectCommand.java b/src/main/java/seedu/duke/command/IncorrectCommand.java
new file mode 100644
index 0000000000..2549dae15c
--- /dev/null
+++ b/src/main/java/seedu/duke/command/IncorrectCommand.java
@@ -0,0 +1,17 @@
+package seedu.duke.command;
+
+/**
+ * Represents an incorrect command. Upon execution, produces some feedback to the user.
+ */
+public class IncorrectCommand extends Command{
+ public final String feedbackToUser;
+
+ public IncorrectCommand(String feedbackToUser) {
+ this.feedbackToUser = feedbackToUser;
+ }
+
+ @Override
+ public void execute() {
+ //ui.showToUser(feedbackToUser);
+ }
+}
diff --git a/src/main/java/seedu/duke/command/ListCommand.java b/src/main/java/seedu/duke/command/ListCommand.java
deleted file mode 100644
index f6434ba82b..0000000000
--- a/src/main/java/seedu/duke/command/ListCommand.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package seedu.duke.command;
-
-/**
- * Lists all tasks in the menu to the user.
- */
-public class ListCommand extends Command {
- @Override
- public void execute() {
-
- };
-}
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
new file mode 100644
index 0000000000..5d539c00ff
--- /dev/null
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -0,0 +1,11 @@
+package seedu.duke.command;
+
+/**
+ * Lists all ingredients used in the selected dish to the user.
+ */
+public class ListIngredientCommand extends Command{
+ @Override
+ public void execute() {
+
+ };
+}
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
new file mode 100644
index 0000000000..68445dc1fc
--- /dev/null
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -0,0 +1,11 @@
+package seedu.duke.command;
+
+/**
+ * Lists all dishes in the menu to the user.
+ */
+public class ListMenuCommand extends Command {
+ @Override
+ public void execute() {
+
+ };
+}
diff --git a/src/test/java/seedu/duke/command/AddCommandTest.java b/src/test/java/seedu/duke/command/AddCommandTest.java
deleted file mode 100644
index 8f3c90e8c5..0000000000
--- a/src/test/java/seedu/duke/command/AddCommandTest.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package seedu.duke.command;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-class AddCommandTest {
-
-}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/AddDishCommandTest.java b/src/test/java/seedu/duke/command/AddDishCommandTest.java
new file mode 100644
index 0000000000..5740f2f803
--- /dev/null
+++ b/src/test/java/seedu/duke/command/AddDishCommandTest.java
@@ -0,0 +1,5 @@
+package seedu.duke.command;
+
+class AddDishCommandTest {
+
+}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/CommandTest.java b/src/test/java/seedu/duke/command/CommandTest.java
index 57c9cbb950..7088764994 100644
--- a/src/test/java/seedu/duke/command/CommandTest.java
+++ b/src/test/java/seedu/duke/command/CommandTest.java
@@ -1,7 +1,5 @@
package seedu.duke.command;
-import static org.junit.jupiter.api.Assertions.*;
-
class CommandTest {
}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/DeleteCommandTest.java b/src/test/java/seedu/duke/command/DeleteCommandTest.java
deleted file mode 100644
index db8409d2b5..0000000000
--- a/src/test/java/seedu/duke/command/DeleteCommandTest.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package seedu.duke.command;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-class DeleteCommandTest {
-
-}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/DeleteDishCommandTest.java b/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
new file mode 100644
index 0000000000..ea9e3f83bc
--- /dev/null
+++ b/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
@@ -0,0 +1,5 @@
+package seedu.duke.command;
+
+class DeleteDishCommandTest {
+
+}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/ListCommandTest.java b/src/test/java/seedu/duke/command/ListCommandTest.java
deleted file mode 100644
index df416b34d0..0000000000
--- a/src/test/java/seedu/duke/command/ListCommandTest.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package seedu.duke.command;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-class ListCommandTest {
-
-}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/ListIngredientCommandTest.java b/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
new file mode 100644
index 0000000000..4d48b6bb5f
--- /dev/null
+++ b/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
@@ -0,0 +1,5 @@
+package seedu.duke.command;
+
+class ListIngredientCommandTest {
+
+}
\ No newline at end of file
diff --git a/src/test/java/seedu/duke/command/ListMenuCommandTest.java b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
new file mode 100644
index 0000000000..513e7e9f57
--- /dev/null
+++ b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
@@ -0,0 +1,5 @@
+package seedu.duke.command;
+
+class ListMenuCommandTest {
+
+}
\ No newline at end of file
From eb08e382fa90c0fb9bdf8e71b309f20284cd98ad Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 12:40:12 +0800
Subject: [PATCH 025/870] Add newline at end of test files
---
src/test/java/seedu/duke/command/AddDishCommandTest.java | 2 +-
src/test/java/seedu/duke/command/CommandTest.java | 2 +-
src/test/java/seedu/duke/command/DeleteDishCommandTest.java | 2 +-
src/test/java/seedu/duke/command/ListIngredientCommandTest.java | 2 +-
src/test/java/seedu/duke/command/ListMenuCommandTest.java | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/test/java/seedu/duke/command/AddDishCommandTest.java b/src/test/java/seedu/duke/command/AddDishCommandTest.java
index 5740f2f803..70ef96c235 100644
--- a/src/test/java/seedu/duke/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/duke/command/AddDishCommandTest.java
@@ -2,4 +2,4 @@
class AddDishCommandTest {
-}
\ No newline at end of file
+}
diff --git a/src/test/java/seedu/duke/command/CommandTest.java b/src/test/java/seedu/duke/command/CommandTest.java
index 7088764994..f63ea17f26 100644
--- a/src/test/java/seedu/duke/command/CommandTest.java
+++ b/src/test/java/seedu/duke/command/CommandTest.java
@@ -2,4 +2,4 @@
class CommandTest {
-}
\ No newline at end of file
+}
diff --git a/src/test/java/seedu/duke/command/DeleteDishCommandTest.java b/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
index ea9e3f83bc..b76f003c48 100644
--- a/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
+++ b/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
@@ -2,4 +2,4 @@
class DeleteDishCommandTest {
-}
\ No newline at end of file
+}
diff --git a/src/test/java/seedu/duke/command/ListIngredientCommandTest.java b/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
index 4d48b6bb5f..7247a13efb 100644
--- a/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
@@ -2,4 +2,4 @@
class ListIngredientCommandTest {
-}
\ No newline at end of file
+}
diff --git a/src/test/java/seedu/duke/command/ListMenuCommandTest.java b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
index 513e7e9f57..46fa38d7da 100644
--- a/src/test/java/seedu/duke/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
@@ -2,4 +2,4 @@
class ListMenuCommandTest {
-}
\ No newline at end of file
+}
From 3c06e5aa4557a25d90dda38e1a41ae36ca9e6e10 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 14:54:14 +0800
Subject: [PATCH 026/870] Update execute method in Command class
---
src/main/java/seedu/duke/command/AddDishCommand.java | 5 ++++-
src/main/java/seedu/duke/command/Command.java | 5 ++++-
src/main/java/seedu/duke/command/DeleteDishCommand.java | 5 ++++-
src/main/java/seedu/duke/command/IncorrectCommand.java | 5 ++++-
src/main/java/seedu/duke/command/ListIngredientCommand.java | 5 ++++-
src/main/java/seedu/duke/command/ListMenuCommand.java | 5 ++++-
6 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
index cd956af6f2..4ac249c333 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -1,11 +1,14 @@
package seedu.duke.command;
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
/**
* Adds a menu item to the user
*/
public class AddDishCommand extends Command{
@Override
- public void execute() {
+ public void execute(Menu menu, Ui ui) {
};
}
diff --git a/src/main/java/seedu/duke/command/Command.java b/src/main/java/seedu/duke/command/Command.java
index b2115a9f93..001e239ee4 100644
--- a/src/main/java/seedu/duke/command/Command.java
+++ b/src/main/java/seedu/duke/command/Command.java
@@ -1,5 +1,8 @@
package seedu.duke.command;
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
/**
* Represents an executable command.
*/
@@ -7,7 +10,7 @@ public class Command {
/**
* Executes the command and returns the result.
*/
- public void execute() {
+ public void execute(Menu menu, Ui ui) {
throw new UnsupportedOperationException("This method is to be implemented by child classes");
};
}
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index 5447402c3d..fe3932cbaa 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -1,12 +1,15 @@
package seedu.duke.command;
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
/**
* Deletes a menu item identified using it's last displayed index from the menu.
*/
public class DeleteDishCommand extends Command {
@Override
- public void execute() {
+ public void execute(Menu menu, Ui ui) {
};
}
diff --git a/src/main/java/seedu/duke/command/IncorrectCommand.java b/src/main/java/seedu/duke/command/IncorrectCommand.java
index 2549dae15c..e805d4dc12 100644
--- a/src/main/java/seedu/duke/command/IncorrectCommand.java
+++ b/src/main/java/seedu/duke/command/IncorrectCommand.java
@@ -1,5 +1,8 @@
package seedu.duke.command;
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
/**
* Represents an incorrect command. Upon execution, produces some feedback to the user.
*/
@@ -11,7 +14,7 @@ public IncorrectCommand(String feedbackToUser) {
}
@Override
- public void execute() {
+ public void execute(Menu menu, Ui ui) {
//ui.showToUser(feedbackToUser);
}
}
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 5d539c00ff..1941f878bb 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -1,11 +1,14 @@
package seedu.duke.command;
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
/**
* Lists all ingredients used in the selected dish to the user.
*/
public class ListIngredientCommand extends Command{
@Override
- public void execute() {
+ public void execute(Menu menu, Ui ui) {
};
}
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
index 68445dc1fc..0bc6403a3c 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -1,11 +1,14 @@
package seedu.duke.command;
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
/**
* Lists all dishes in the menu to the user.
*/
public class ListMenuCommand extends Command {
@Override
- public void execute() {
+ public void execute(Menu menu, Ui ui) {
};
}
From 07a56ed80238819e5d1923bc0495342718d6cc60 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 15:14:05 +0800
Subject: [PATCH 027/870] Update Command class to include index attribute
---
src/main/java/seedu/duke/command/Command.java | 7 +++++++
src/main/java/seedu/duke/command/ListMenuCommand.java | 5 ++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/Command.java b/src/main/java/seedu/duke/command/Command.java
index 001e239ee4..ec80de13f6 100644
--- a/src/main/java/seedu/duke/command/Command.java
+++ b/src/main/java/seedu/duke/command/Command.java
@@ -7,6 +7,13 @@
* Represents an executable command.
*/
public class Command {
+
+ private int index;
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
/**
* Executes the command and returns the result.
*/
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
index 0bc6403a3c..72ef58ccd4 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -1,6 +1,7 @@
package seedu.duke.command;
import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
import seedu.duke.ui.Ui;
/**
@@ -9,6 +10,8 @@
public class ListMenuCommand extends Command {
@Override
public void execute(Menu menu, Ui ui) {
-
+/* for (String d : menu) {
+ System.out.println(d);
+ }*/
};
}
From 0571dea28a7a323f5ea3157b5b11efc77a16ad9d Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 15:31:47 +0800
Subject: [PATCH 028/870] Update ListMenuCommand.java for spacing issue
---
src/main/java/seedu/duke/command/ListMenuCommand.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
index 72ef58ccd4..12a8f57d4c 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -1,7 +1,7 @@
package seedu.duke.command;
import seedu.duke.data.Menu;
-import seedu.duke.data.dish.Dish;
+//import seedu.duke.data.dish.Dish;
import seedu.duke.ui.Ui;
/**
@@ -10,7 +10,7 @@
public class ListMenuCommand extends Command {
@Override
public void execute(Menu menu, Ui ui) {
-/* for (String d : menu) {
+ /*for (String d : menu) {
System.out.println(d);
}*/
};
From 67f65e2b750751127920b80b45d162c28849b99f Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 16 Oct 2023 22:17:06 +0800
Subject: [PATCH 029/870] Update Menu.java methods
---
src/main/java/seedu/duke/data/Menu.java | 12 ++++++++++++
src/main/java/seedu/duke/ui/UserOutput.java | 3 ++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
index f5317a3d44..e40e6036a6 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -10,4 +10,16 @@ public class Menu {
public Menu(ArrayList menuItems) {
this.menuItems = menuItems;
}
+ public int getSize() {
+ return menuItems.size();
+ }
+ public Dish getDish(int menuID) {
+ return menuItems.get(menuID);
+ }
+ public void remove(int menuID) {
+ menuItems.remove(menuID);
+ }
+ public void add(Dish dish) {
+ menuItems.add(dish);
+ }
}
diff --git a/src/main/java/seedu/duke/ui/UserOutput.java b/src/main/java/seedu/duke/ui/UserOutput.java
index 19c248a4de..2087e9256c 100644
--- a/src/main/java/seedu/duke/ui/UserOutput.java
+++ b/src/main/java/seedu/duke/ui/UserOutput.java
@@ -5,7 +5,8 @@
*/
public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
- GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!");
+ GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
+ LIST_MESSAGE("Ah, behold, the grand menu of delights! 🍽️");
public final String message;
UserOutput(String message) {
From 8e4fb479ae61dfc19385dee50a5acffe9072dd7d Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Mon, 16 Oct 2023 22:36:13 +0800
Subject: [PATCH 030/870] Add commonly used methods
---
src/main/java/seedu/duke/data/Menu.java | 12 ++++++++++++
src/main/java/seedu/duke/data/dish/Dish.java | 12 ++++++++++++
src/main/java/seedu/duke/data/dish/Ingredient.java | 12 ++++++++++++
src/main/java/seedu/duke/ui/Ui.java | 6 ++++++
4 files changed, 42 insertions(+)
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
index f5317a3d44..e40e6036a6 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -10,4 +10,16 @@ public class Menu {
public Menu(ArrayList menuItems) {
this.menuItems = menuItems;
}
+ public int getSize() {
+ return menuItems.size();
+ }
+ public Dish getDish(int menuID) {
+ return menuItems.get(menuID);
+ }
+ public void remove(int menuID) {
+ menuItems.remove(menuID);
+ }
+ public void add(Dish dish) {
+ menuItems.add(dish);
+ }
}
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/duke/data/dish/Dish.java
index 07f883c7ed..f6bf60a89d 100644
--- a/src/main/java/seedu/duke/data/dish/Dish.java
+++ b/src/main/java/seedu/duke/data/dish/Dish.java
@@ -12,4 +12,16 @@ public Dish(String name, ArrayList ingredients, float price) {
this.ingredients = ingredients;
this.price = price;
}
+
+ public String getName() {
+ return name;
+ }
+
+ public ArrayList getIngredients() {
+ return ingredients;
+ }
+
+ public float getPrice() {
+ return price;
+ }
}
diff --git a/src/main/java/seedu/duke/data/dish/Ingredient.java b/src/main/java/seedu/duke/data/dish/Ingredient.java
index 11478bc98a..4f200e57ee 100644
--- a/src/main/java/seedu/duke/data/dish/Ingredient.java
+++ b/src/main/java/seedu/duke/data/dish/Ingredient.java
@@ -2,8 +2,20 @@
public class Ingredient {
private final String name;
+ private final String quantity;
public Ingredient(String name) {
this.name = name;
+ quantity = null;
+ }
+
+ public Ingredient(String name, String quantity) {
+ this.name = name;
+ this.quantity = quantity;
+ }
+
+ @Override
+ public String toString() {
+ return name + " - " + quantity;
}
}
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 298654281f..e9e9270ca0 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -23,4 +23,10 @@ public void showWelcome() {
public void showGoodbye() {
System.out.println(UserOutput.GOODBYE_MESSAGE.message);
}
+ /** Shows messages(s) to the user **/
+ public void showToUser(String... message) {
+ for (String m: message) {
+ System.out.println(m);
+ }
+ }
}
From f97b53934e0c8778b06897e07499db1182d9365f Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Mon, 16 Oct 2023 22:41:32 +0800
Subject: [PATCH 031/870] Add getters for Ingredient class
---
src/main/java/seedu/duke/data/dish/Ingredient.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/main/java/seedu/duke/data/dish/Ingredient.java b/src/main/java/seedu/duke/data/dish/Ingredient.java
index 4f200e57ee..6089bea27a 100644
--- a/src/main/java/seedu/duke/data/dish/Ingredient.java
+++ b/src/main/java/seedu/duke/data/dish/Ingredient.java
@@ -14,6 +14,14 @@ public Ingredient(String name, String quantity) {
this.quantity = quantity;
}
+ public String getName() {
+ return name;
+ }
+
+ public String getQuantity() {
+ return quantity;
+ }
+
@Override
public String toString() {
return name + " - " + quantity;
From c4e118ce054a0eed4b0d076aadeaf5059f04853a Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 00:01:14 +0800
Subject: [PATCH 032/870] Add delete message to Ui class
---
src/main/java/seedu/duke/ui/Ui.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index e9e9270ca0..5c5c8ebe12 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -23,6 +23,11 @@ public void showWelcome() {
public void showGoodbye() {
System.out.println(UserOutput.GOODBYE_MESSAGE.message);
}
+
+ public void showDeleteMessage(String menuItem) {
+ showToUser("Okies! " + menuItem + " deleted! :)");
+ }
+
/** Shows messages(s) to the user **/
public void showToUser(String... message) {
for (String m: message) {
From 93ca9601f61702c86011451a21e6c3a097ff8f11 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 00:03:29 +0800
Subject: [PATCH 033/870] Fixes #21
Add javadoc to delete message method
---
src/main/java/seedu/duke/ui/Ui.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 5c5c8ebe12..61d84f6866 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -24,6 +24,11 @@ public void showGoodbye() {
System.out.println(UserOutput.GOODBYE_MESSAGE.message);
}
+ /**
+ * Shows delete message to user
+ *
+ * @param menuItem String of menu item deleted
+ */
public void showDeleteMessage(String menuItem) {
showToUser("Okies! " + menuItem + " deleted! :)");
}
From b1c8b3917bf5d9a2969b2dfcc85a77ed902bb5ab Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Tue, 17 Oct 2023 00:10:50 +0800
Subject: [PATCH 034/870] Add list ingredient command.
#Fixes 20
---
.../seedu/duke/command/ListIngredientCommand.java | 2 +-
src/main/java/seedu/duke/data/Menu.java | 4 ++++
src/main/java/seedu/duke/data/dish/Dish.java | 5 +++++
src/main/java/seedu/duke/data/dish/Ingredient.java | 1 +
src/main/java/seedu/duke/ui/Ui.java | 14 ++++++++++++++
5 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 1941f878bb..79c6b400b0 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -9,6 +9,6 @@
public class ListIngredientCommand extends Command{
@Override
public void execute(Menu menu, Ui ui) {
-
+ Ui.listIngredients(menu);
};
}
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
index f5317a3d44..45e0e38735 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -10,4 +10,8 @@ public class Menu {
public Menu(ArrayList menuItems) {
this.menuItems = menuItems;
}
+
+ public ArrayList getMenuItemsList() {
+ return menuItems;
+ }
}
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/duke/data/dish/Dish.java
index 07f883c7ed..bbbd8dd5b8 100644
--- a/src/main/java/seedu/duke/data/dish/Dish.java
+++ b/src/main/java/seedu/duke/data/dish/Dish.java
@@ -12,4 +12,9 @@ public Dish(String name, ArrayList ingredients, float price) {
this.ingredients = ingredients;
this.price = price;
}
+
+
+ public ArrayList getIngredients() {
+ return ingredients;
+ }
}
diff --git a/src/main/java/seedu/duke/data/dish/Ingredient.java b/src/main/java/seedu/duke/data/dish/Ingredient.java
index 11478bc98a..d8387088bf 100644
--- a/src/main/java/seedu/duke/data/dish/Ingredient.java
+++ b/src/main/java/seedu/duke/data/dish/Ingredient.java
@@ -6,4 +6,5 @@ public class Ingredient {
public Ingredient(String name) {
this.name = name;
}
+
}
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 298654281f..287befb5a3 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -1,5 +1,8 @@
package seedu.duke.ui;
+import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
+
import java.util.Scanner;
public class Ui {
@@ -23,4 +26,15 @@ public void showWelcome() {
public void showGoodbye() {
System.out.println(UserOutput.GOODBYE_MESSAGE.message);
}
+
+ public static void listIngredients(Menu menu) {
+ int index = 0;
+ for (Dish dish : menu.getMenuItemsList()) {
+ if (dish != null) {
+ System.out.print(" " + ++index + ". ");
+ System.out.println(dish);
+ dish.getIngredients().forEach(System.out::println);
+ }
+ }
+ }
}
From f079f9950ec7a31a8ce26b0cf50c5a7507d3dd6f Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 00:14:48 +0800
Subject: [PATCH 035/870] Implement parseCommand() method according to
AddressbookLevel2
---
src/main/java/seedu/duke/parser/Parser.java | 37 +++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index e23fe0ca92..882eec6db4 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -1,9 +1,46 @@
package seedu.duke.parser;
+import seedu.duke.command.Command;
+import seedu.duke.command.ListIngredientCommand;
+import seedu.duke.command.ListMenuCommand;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Parse everything received from the users on terminal
* into a format that can be interpreted by other core classes
*/
public class Parser {
+ public static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?\\S+)(?.*)");
+ final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim());
+ if (!matcher.matches()) {
+ return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
+ }
+
+ final String commandWord = matcher.group("commandWord");
+ final String arguments = matcher.group("arguments");
+
+ public Command parseCommand(String userInput) {
+ switch (commandWord) {
+
+ case AddDishCommand.COMMAND_WORD:
+ return prepareAdd(arguments);
+
+ case DeleteDishCommand.COMMAND_WORD:
+ return prepareDelete(arguments);
+
+ case EditPriceCommand.COMMAND_WORD:
+ return new ClearCommand();
+
+ case ListIngredientCommand.COMMAND_WORD:
+ return prepareFind(arguments);
+
+ case ListMenuCommand.COMMAND_WORD:
+ return new ListCommand();
+ default:
+ return new HelpCommand();
+ }
+ }
}
From 0852e29a9ee8563ff84a34e75b5b0efd5b342e09 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 00:24:24 +0800
Subject: [PATCH 036/870] Implement ui support for edit price feature
fixes #14
---
src/main/java/seedu/duke/ui/Ui.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index e9e9270ca0..347821a57d 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -29,4 +29,9 @@ public void showToUser(String... message) {
System.out.println(m);
}
}
+
+ public void showEditPriceMessage(String menuItem) {
+ System.out.println("Modified the following dish: ");
+ showToUser(menuItem);
+ }
}
From 0dcf6106d09cef97c0c807f356e3a62be9043b33 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 00:25:13 +0800
Subject: [PATCH 037/870] Dish.java: add setter for price
---
src/main/java/seedu/duke/data/dish/Dish.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/duke/data/dish/Dish.java
index f6bf60a89d..83e3149963 100644
--- a/src/main/java/seedu/duke/data/dish/Dish.java
+++ b/src/main/java/seedu/duke/data/dish/Dish.java
@@ -24,4 +24,8 @@ public ArrayList getIngredients() {
public float getPrice() {
return price;
}
+
+ public void setPrice(float newPrice) {
+ this.price = newPrice;
+ }
}
From b67df48ceadf6e7b7d4972f4ab094428396d9293 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 00:30:07 +0800
Subject: [PATCH 038/870] Create EditPriceCommand.java
---
.../seedu/duke/command/EditPriceCommand.java | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 src/main/java/seedu/duke/command/EditPriceCommand.java
diff --git a/src/main/java/seedu/duke/command/EditPriceCommand.java b/src/main/java/seedu/duke/command/EditPriceCommand.java
new file mode 100644
index 0000000000..766ca15fce
--- /dev/null
+++ b/src/main/java/seedu/duke/command/EditPriceCommand.java
@@ -0,0 +1,21 @@
+package seedu.duke.command;
+
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
+/**
+ * Edit the price of a dish of a certain index
+ */
+public class EditPriceCommand extends Command {
+ private final int menuID;
+ private final float newPrice;
+
+ public EditPriceCommand(int menuID, float newPrice) {
+ this.menuID = menuID;
+ this.newPrice = newPrice;
+ }
+
+ public void execute(Menu menu, Ui ui) {
+ menu.getDish(this.menuID).setPrice(this.newPrice);
+ }
+}
From 74f4f4d8f197fab8035bc1e7a855ccbd426dfc11 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 00:34:52 +0800
Subject: [PATCH 039/870] Implement add dish feature
---
.../seedu/duke/command/AddDishCommand.java | 12 +++++--
src/main/java/seedu/duke/data/Menu.java | 4 +--
src/main/java/seedu/duke/ui/Ui.java | 31 ++++++++++++++++++-
src/main/java/seedu/duke/ui/UserOutput.java | 3 +-
4 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
index 4ac249c333..eecbee8d82 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -1,14 +1,20 @@
package seedu.duke.command;
import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
import seedu.duke.ui.Ui;
/**
* Adds a menu item to the user
*/
-public class AddDishCommand extends Command{
+public class AddDishCommand extends Command {
+ Dish dish;
+ public AddDishCommand(Dish dish) {
+ this.dish = dish;
+ }
@Override
public void execute(Menu menu, Ui ui) {
-
- };
+ menu.addDish(dish);
+ ui.printAddDishMessage(dish);
+ }
}
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
index e40e6036a6..e3941873a6 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -16,10 +16,10 @@ public int getSize() {
public Dish getDish(int menuID) {
return menuItems.get(menuID);
}
- public void remove(int menuID) {
+ public void removeDish(int menuID) {
menuItems.remove(menuID);
}
- public void add(Dish dish) {
+ public void addDish(Dish dish) {
menuItems.add(dish);
}
}
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index e9e9270ca0..7d7dbe177c 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -1,8 +1,12 @@
package seedu.duke.ui;
+import seedu.duke.data.dish.Dish;
+import seedu.duke.data.dish.Ingredient;
+
import java.util.Scanner;
public class Ui {
+ public static final int OFFSET_LIST_INDEX = 1;
private final Scanner scanner;
/**
@@ -23,7 +27,32 @@ public void showWelcome() {
public void showGoodbye() {
System.out.println(UserOutput.GOODBYE_MESSAGE.message);
}
- /** Shows messages(s) to the user **/
+
+ public void printAddDishMessage(Dish dish) {
+ String dishNameString = "Dish Name: " + dish.getName();
+ String dishPriceString = "Dish Price: $" + dish.getPrice();
+ StringBuilder dishIngredientsString = new StringBuilder("Ingredients:\n");
+
+ for (int i = 0; i < dish.getIngredients().size(); i++) {
+ Ingredient ingredient = dish.getIngredients().get(i);
+
+ dishIngredientsString.append("\t")
+ .append(i + OFFSET_LIST_INDEX)
+ .append(". ")
+ .append(ingredient.toString())
+ .append("\n");
+ }
+
+ showToUser(UserOutput.ADD_DISH_MESSAGE.message,
+ dishNameString,
+ dishPriceString,
+ dishIngredientsString.toString());
+ }
+
+ /**
+ * Shows messages(s) to the user
+ * @param message string(s) of messages to print
+ */
public void showToUser(String... message) {
for (String m: message) {
System.out.println(m);
diff --git a/src/main/java/seedu/duke/ui/UserOutput.java b/src/main/java/seedu/duke/ui/UserOutput.java
index 19c248a4de..076c2852e3 100644
--- a/src/main/java/seedu/duke/ui/UserOutput.java
+++ b/src/main/java/seedu/duke/ui/UserOutput.java
@@ -5,7 +5,8 @@
*/
public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
- GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!");
+ GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
+ ADD_DISH_MESSAGE("You have added the following dish...");
public final String message;
UserOutput(String message) {
From 188ec8e7c0cd4b376b7ab20baa1b24b4b3a9fce0 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 01:24:14 +0800
Subject: [PATCH 040/870] Update ListMenuCommand.java function
Fixes #16
---
.../seedu/duke/command/ListMenuCommand.java | 21 +++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
index 12a8f57d4c..84d0e706a2 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -1,17 +1,30 @@
package seedu.duke.command;
import seedu.duke.data.Menu;
-//import seedu.duke.data.dish.Dish;
import seedu.duke.ui.Ui;
+import seedu.duke.ui.UserOutput;
+
+import java.text.DecimalFormat;
/**
* Lists all dishes in the menu to the user.
*/
public class ListMenuCommand extends Command {
+ private static final DecimalFormat dollarValue = new DecimalFormat("0.00");
+ /**
+ * Iterates through the menu arraylist, outputting the dish name and dish price.
+ *
+ * @param menu ArrayList of Dishes
+ * @param ui Handles the interactions with user
+ */
@Override
public void execute(Menu menu, Ui ui) {
- /*for (String d : menu) {
- System.out.println(d);
- }*/
+ ui.showToUser(UserOutput.LIST_MESSAGE.message);
+ for(int i =0; i < menu.getSize(); i++) {
+ String indexNum = String.valueOf(i+1);
+ String dishName = menu.getDish(i).getName();
+ String dishPrice = dollarValue.format(menu.getDish(i).getPrice());
+ ui.showToUser(indexNum + "." + dishName + " $" + dishPrice);
+ }
};
}
From 960269b67e4aa999773ea1f4dbc28795c369f061 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 01:25:16 +0800
Subject: [PATCH 041/870] Implement UI support for ListMenu
Fixes #18
---
src/main/java/seedu/duke/ui/Ui.java | 1 +
src/main/java/seedu/duke/ui/UserOutput.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index e9e9270ca0..9f4ef2bc38 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -23,6 +23,7 @@ public void showWelcome() {
public void showGoodbye() {
System.out.println(UserOutput.GOODBYE_MESSAGE.message);
}
+
/** Shows messages(s) to the user **/
public void showToUser(String... message) {
for (String m: message) {
diff --git a/src/main/java/seedu/duke/ui/UserOutput.java b/src/main/java/seedu/duke/ui/UserOutput.java
index 2087e9256c..3b6f69e1e4 100644
--- a/src/main/java/seedu/duke/ui/UserOutput.java
+++ b/src/main/java/seedu/duke/ui/UserOutput.java
@@ -6,7 +6,7 @@
public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
- LIST_MESSAGE("Ah, behold, the grand menu of delights! 🍽️");
+ LIST_MESSAGE("Ah, behold, the grand menu of delights!");
public final String message;
UserOutput(String message) {
From 812654327335924346f337a4102942a40b05df4e Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 01:44:54 +0800
Subject: [PATCH 042/870] Edit delete message
---
src/main/java/seedu/duke/ui/Ui.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 61d84f6866..9dc129ec49 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -30,7 +30,7 @@ public void showGoodbye() {
* @param menuItem String of menu item deleted
*/
public void showDeleteMessage(String menuItem) {
- showToUser("Okies! " + menuItem + " deleted! :)");
+ showToUser("Okay! " + menuItem + " is deleted! :)");
}
/** Shows messages(s) to the user **/
From ddd3d5049a361d1bc8b66e1fc77f7b4ea24ed638 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 01:46:09 +0800
Subject: [PATCH 043/870] Update delete command
---
.../java/seedu/duke/command/DeleteDishCommand.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index fe3932cbaa..48fea6ab9d 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -8,8 +8,20 @@
*/
public class DeleteDishCommand extends Command {
+ private int dishIndex;
+
+ /**
+ * Constructor for DeleteDishCommand
+ *
+ * @param index index of menu item to be deleted
+ */
+ public DeleteDishCommand(int index) {
+ this.dishIndex = index;
+ }
+
@Override
public void execute(Menu menu, Ui ui) {
-
+ menu.remove(dishIndex);
+ ui.showDeleteMessage(menu.getDish(dishIndex).toString());
};
}
From ad6b223efae6bf4be468bf1ad7cbeb772c58d774 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 02:14:22 +0800
Subject: [PATCH 044/870] Implement Junit for ListCommand.java
---
src/main/java/seedu/duke/data/dish/Dish.java | 5 +++++
.../seedu/duke/command/ListMenuCommandTest.java | 16 ++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/duke/data/dish/Dish.java
index f6bf60a89d..f188bc44ee 100644
--- a/src/main/java/seedu/duke/data/dish/Dish.java
+++ b/src/main/java/seedu/duke/data/dish/Dish.java
@@ -12,6 +12,11 @@ public Dish(String name, ArrayList ingredients, float price) {
this.ingredients = ingredients;
this.price = price;
}
+ public Dish(String name, float price) {
+ this.name = name;
+ this.ingredients = null;
+ this.price = price;
+ }
public String getName() {
return name;
diff --git a/src/test/java/seedu/duke/command/ListMenuCommandTest.java b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
index 46fa38d7da..2fd34e4af8 100644
--- a/src/test/java/seedu/duke/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
@@ -1,5 +1,21 @@
package seedu.duke.command;
+import org.junit.jupiter.api.Test;
+import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
+import seedu.duke.ui.Ui;
+
+import java.util.ArrayList;
+
class ListMenuCommandTest {
+ @Test
+ public static void main(String[] args) {
+ ArrayList menuItems = new ArrayList<>();
+ menuItems.add(new Dish("Chicken Rice", 2.50F));
+ menuItems.add(new Dish("Chicken Curry", 4.30F));
+ Menu menu = new Menu(menuItems);
+ Command ListMenuCommand = new ListMenuCommand();
+ ListMenuCommand.execute(menu, new Ui());
+ }
}
From ac4e57130e2e050f03f1ccd7411de2e88ee69082 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 02:17:29 +0800
Subject: [PATCH 045/870] Update ListMenuCommand.java
---
.../java/seedu/duke/command/ListMenuCommand.java | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
index 12a8f57d4c..0532dc273b 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -4,10 +4,22 @@
//import seedu.duke.data.dish.Dish;
import seedu.duke.ui.Ui;
+import java.text.DecimalFormat;
+
/**
* Lists all dishes in the menu to the user.
*/
public class ListMenuCommand extends Command {
+
+ public static final String COMMAND_WORD = "list_menu";
+ private static final DecimalFormat dollarValue = new DecimalFormat("0.00");
+ /**
+ * Iterates through the menu arraylist, outputting the dish name and dish price.
+ *
+ * @param menu ArrayList of Dishes
+ * @param ui Handles the interactions with user
+ */
+
@Override
public void execute(Menu menu, Ui ui) {
/*for (String d : menu) {
From f6297af60c900eefedcceacecce2d08c15276341 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 02:31:37 +0800
Subject: [PATCH 046/870] Update ListMenuCommandTest.java
---
src/test/java/seedu/duke/command/ListMenuCommandTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/seedu/duke/command/ListMenuCommandTest.java b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
index 2fd34e4af8..8e517c173a 100644
--- a/src/test/java/seedu/duke/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
@@ -9,7 +9,7 @@
class ListMenuCommandTest {
@Test
- public static void main(String[] args) {
+ public static void execute_outputTwoDishes_() {
ArrayList menuItems = new ArrayList<>();
menuItems.add(new Dish("Chicken Rice", 2.50F));
menuItems.add(new Dish("Chicken Curry", 4.30F));
From 2856c5f60c980e91be95c745fedd8c9e8ddd6e31 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 02:32:37 +0800
Subject: [PATCH 047/870] Implement Parser Class
---
src/main/java/seedu/duke/Duke.java | 35 +++++---
.../seedu/duke/command/AddDishCommand.java | 1 +
.../seedu/duke/command/DeleteDishCommand.java | 6 +-
.../java/seedu/duke/command/ExitCommand.java | 18 +++++
.../duke/command/ListIngredientCommand.java | 5 ++
.../seedu/duke/command/ListMenuCommand.java | 1 +
src/main/java/seedu/duke/parser/Parser.java | 80 +++++++++++++++++++
7 files changed, 136 insertions(+), 10 deletions(-)
create mode 100644 src/main/java/seedu/duke/command/ExitCommand.java
diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java
index 5c74e68d59..87b920c350 100644
--- a/src/main/java/seedu/duke/Duke.java
+++ b/src/main/java/seedu/duke/Duke.java
@@ -1,21 +1,38 @@
package seedu.duke;
+import seedu.duke.command.Command;
+import seedu.duke.data.Menu;
+import seedu.duke.parser.Parser;
+import seedu.duke.ui.Ui;
+import seedu.duke.command.ExitCommand;
+
import java.util.Scanner;
public class Duke {
/**
* Main entry-point for the java.duke.Duke application.
*/
+ private Ui ui;
+ private Menu menu;
public static void main(String[] args) {
- String logo = " ____ _ \n"
- + "| _ \\ _ _| | _____ \n"
- + "| | | | | | | |/ / _ \\\n"
- + "| |_| | |_| | < __/\n"
- + "|____/ \\__,_|_|\\_\\___|\n";
- System.out.println("Hello from\n" + logo);
- System.out.println("What is your name?");
+ new Duke().run();
+ }
- Scanner in = new Scanner(System.in);
- System.out.println("Hello " + in.nextLine());
+ /** Runs the program until termination. */
+ public void run() {
+ runCommandLoopUntilExitCommand();
+ exit(ui);
+ }
+ /** Reads the user command and executes it, until the user issues the exit command. */
+ public void runCommandLoopUntilExitCommand() {
+ do {
+ String item = ui.receiveUserInput();
+ Command c = Parser.parseCommand(menu, item);
+ c.execute(menu, ui);
+ } while (!ExitCommand.isExit());
+ }
+ private static void exit(Ui ui) {
+ ui.showGoodbye();
+ System.exit(0);
}
}
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
index 4ac249c333..bdf3b47a33 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -7,6 +7,7 @@
* Adds a menu item to the user
*/
public class AddDishCommand extends Command{
+ public static final String COMMAND_WORD = "add";
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index fe3932cbaa..0f965242f6 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -7,7 +7,11 @@
* Deletes a menu item identified using it's last displayed index from the menu.
*/
public class DeleteDishCommand extends Command {
-
+ public static final String COMMAND_WORD = "delete";
+ public static final String MESSAGE_USAGE = COMMAND_WORD
+ + ": Deletes the menu item identified by the index number used in the last menu listing.\n"
+ + "Parameters: INDEX\n"
+ + "Example: " + COMMAND_WORD + " 1";
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/command/ExitCommand.java b/src/main/java/seedu/duke/command/ExitCommand.java
new file mode 100644
index 0000000000..cc74c10ea4
--- /dev/null
+++ b/src/main/java/seedu/duke/command/ExitCommand.java
@@ -0,0 +1,18 @@
+package seedu.duke.command;
+
+import seedu.duke.data.Menu;
+import seedu.duke.ui.Ui;
+
+public class ExitCommand extends Command{
+ protected static boolean isExit = false;
+ public static final String COMMAND_WORD = "bye";
+
+ @Override
+ public void execute(Menu menu, Ui ui) {
+ isExit = true;
+ }
+
+ public static boolean isExit() {
+ return isExit;
+ }
+}
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 1941f878bb..41d0f1b905 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -7,6 +7,11 @@
* Lists all ingredients used in the selected dish to the user.
*/
public class ListIngredientCommand extends Command{
+ public static final String COMMAND_WORD = "list_ingredients";
+ public static final String MESSAGE_USAGE = COMMAND_WORD
+ + ": Lists out the ingredients needed along with the quantity for a specific dish.\n"
+ + "Parameters: INDEX\n"
+ + "Example: " + COMMAND_WORD + " 1";
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
index 84d0e706a2..43ca95e4e2 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -10,6 +10,7 @@
* Lists all dishes in the menu to the user.
*/
public class ListMenuCommand extends Command {
+ public static final String COMMAND_WORD = "list";
private static final DecimalFormat dollarValue = new DecimalFormat("0.00");
/**
* Iterates through the menu arraylist, outputting the dish name and dish price.
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index e23fe0ca92..703f2f1586 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -1,9 +1,89 @@
package seedu.duke.parser;
+import seedu.duke.command.AddDishCommand;
+import seedu.duke.command.Command;
+import seedu.duke.command.DeleteDishCommand;
+import seedu.duke.command.ExitCommand;
+import seedu.duke.command.IncorrectCommand;
+import seedu.duke.command.ListIngredientCommand;
+import seedu.duke.command.ListMenuCommand;
+import seedu.duke.data.Menu;
+
+import java.text.ParseException;
+
/**
* Parse everything received from the users on terminal
* into a format that can be interpreted by other core classes
*/
public class Parser {
+ /**
+ * Parses user input into command for execution.
+ *
+ * @param userInput full user input string
+ * @param menu The arraylist object created that stores current tasks
+ * @return the command based on the user input
+ */
+ public static Command parseCommand(Menu menu, String userInput) {
+ String command[] = userInput.split(" ");
+ switch (command[0].toLowerCase()) {
+ case ListMenuCommand.COMMAND_WORD:
+ return new ListMenuCommand();
+ /*case ListIngredientCommand.COMMAND_WORD:
+ return prepareListIngredient(menu,userInput);
+ case DeleteDishCommand.COMMAND_WORD:
+ return prepareDelete(menu,userInput);*/
+ case ExitCommand.COMMAND_WORD:
+ return new ExitCommand();
+ case AddDishCommand.COMMAND_WORD:
+ return new AddDishCommand();
+ default:
+ return new IncorrectCommand("Whoa there, tiger! Your command has left me scratching my virtual head. Let's try that again, shall we?");
+ }
+ }
+
+ /**
+ *
+ * @param menu
+ * @param userInput
+ * @return the prepared command
+ */
+ private static Command prepareListIngredient(Menu menu, String userInput) {
+ try {
+ final int listIndex = parseArgsAsDisplayedIndex(menu ,userInput, ListIngredientCommand.COMMAND_WORD);
+ //return new ListIngredientCommand(Menu menu, listIndex);
+ return new IncorrectCommand("NAYCHI DO YOUR WORK");
+ } catch (ParseException e) {
+ return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + ListIngredientCommand.MESSAGE_USAGE);
+ } catch (NumberFormatException nfe) {
+ return new IncorrectCommand("MESSAGE_INVALID_TASK_DISPLAYED_INDEX");
+ }
+ }
+
+ private static Command prepareDelete(Menu menu, String userInput) {
+ try {
+ final int listIndex = parseArgsAsDisplayedIndex(menu, userInput, DeleteDishCommand.COMMAND_WORD);
+ //return new DeleteDishCommand(listIndex);
+ return new IncorrectCommand("SHANICE DO YOUR WORK");
+ } catch (ParseException e) {
+ return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE);
+ } catch (NumberFormatException nfe) {
+ return new IncorrectCommand("MESSAGE_INVALID_TASK_DISPLAYED_INDEX");
+ }
+ }
+ /**
+ * Parses the given arguments string to identify task index number.
+ *
+ * @param userInput arguments string to parse as index number
+ * @param command expected String name of the command called
+ * @param menu The arraylist object created that stores current dishes
+ * @return the parsed index number
+ * @throws ParseException if no region of the args string could be found for the index
+ * @throws NumberFormatException the args string region is not a valid number
+ */
+ private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command) throws ParseException, NumberFormatException {
+ String formattedString = userInput.replace(command, "").trim();
+ int listIndex = Integer.parseInt(formattedString);
+ return listIndex;
+ }
}
From 69b789b05598d52130d17ad17ceeec896c42ef5e Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 02:38:26 +0800
Subject: [PATCH 048/870] Add testing for add dish command
Fixes #48
---
.../duke/command/AddDishCommandTest.java | 24 +++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/test/java/seedu/duke/command/AddDishCommandTest.java b/src/test/java/seedu/duke/command/AddDishCommandTest.java
index 70ef96c235..8b2e18bb14 100644
--- a/src/test/java/seedu/duke/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/duke/command/AddDishCommandTest.java
@@ -1,5 +1,29 @@
package seedu.duke.command;
+import org.junit.jupiter.api.Test;
+import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
+import seedu.duke.data.dish.Ingredient;
+import seedu.duke.ui.Ui;
+
+import java.util.ArrayList;
+
+import static org.junit.jupiter.api.Assertions.*;
+
class AddDishCommandTest {
+ @Test
+ void execute_dishAdded_expectDishInMenu() {
+ ArrayList ingredients = new ArrayList<>();
+ ArrayList menuItems = new ArrayList<>();
+ Menu menu = new Menu(menuItems);
+ Ui ui = new Ui();
+ //adding a dish to the menu
+ ingredients.add(new Ingredient("chicken", "100g"));
+ Dish dish = new Dish("Chicken Rice", ingredients, (float) 1.00);
+ AddDishCommand addDishCommand = new AddDishCommand(dish);
+
+ addDishCommand.execute(menu, ui);
+ assertEquals(1, menu.getMenuItemsList().size());
+ }
}
From ca9212eada5e9bc6b5c18f161cb2a8983ccc3a35 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 02:41:44 +0800
Subject: [PATCH 049/870] Edit comment
---
src/test/java/seedu/duke/command/AddDishCommandTest.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/test/java/seedu/duke/command/AddDishCommandTest.java b/src/test/java/seedu/duke/command/AddDishCommandTest.java
index 8b2e18bb14..7a6fbc170f 100644
--- a/src/test/java/seedu/duke/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/duke/command/AddDishCommandTest.java
@@ -17,9 +17,10 @@ void execute_dishAdded_expectDishInMenu() {
ArrayList menuItems = new ArrayList<>();
Menu menu = new Menu(menuItems);
Ui ui = new Ui();
- //adding a dish to the menu
+ //creating a dish
ingredients.add(new Ingredient("chicken", "100g"));
Dish dish = new Dish("Chicken Rice", ingredients, (float) 1.00);
+
AddDishCommand addDishCommand = new AddDishCommand(dish);
addDishCommand.execute(menu, ui);
From b561971875675cd6dbafb42d37fd06e4bf2c8ddf Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 02:32:37 +0800
Subject: [PATCH 050/870] Implement Parser Class
---
src/main/java/seedu/duke/command/AddDishCommand.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
index 4107369c31..0fee423b6c 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -7,7 +7,6 @@
/**
* Adds a menu item to the user
*/
-
public class AddDishCommand extends Command {
Dish dish;
public static final String COMMAND_WORD = "add";
From 9ce30642e1d1acc79672f3dcf830307d7482cf42 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 02:46:04 +0800
Subject: [PATCH 051/870] Update Parser.java
---
src/main/java/seedu/duke/parser/Parser.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 703f2f1586..a5d49af85b 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -35,7 +35,8 @@ public static Command parseCommand(Menu menu, String userInput) {
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
case AddDishCommand.COMMAND_WORD:
- return new AddDishCommand();
+ //return new AddDishCommand();
+ return new IncorrectCommand("DEXTER DO WORK");
default:
return new IncorrectCommand("Whoa there, tiger! Your command has left me scratching my virtual head. Let's try that again, shall we?");
}
From d9714d689f822fffe73a376d3954546775ceaa7d Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 02:56:04 +0800
Subject: [PATCH 052/870] Update code in reference to Gradle
---
src/main/java/seedu/duke/Duke.java | 2 --
.../seedu/duke/command/AddDishCommand.java | 2 +-
.../java/seedu/duke/command/ExitCommand.java | 2 +-
src/main/java/seedu/duke/parser/Parser.java | 34 ++++++++++---------
4 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java
index 87b920c350..a37649b497 100644
--- a/src/main/java/seedu/duke/Duke.java
+++ b/src/main/java/seedu/duke/Duke.java
@@ -6,8 +6,6 @@
import seedu.duke.ui.Ui;
import seedu.duke.command.ExitCommand;
-import java.util.Scanner;
-
public class Duke {
/**
* Main entry-point for the java.duke.Duke application.
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
index 4107369c31..3229fc7393 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -9,8 +9,8 @@
*/
public class AddDishCommand extends Command {
- Dish dish;
public static final String COMMAND_WORD = "add";
+ Dish dish;
public AddDishCommand(Dish dish) {
this.dish = dish;
}
diff --git a/src/main/java/seedu/duke/command/ExitCommand.java b/src/main/java/seedu/duke/command/ExitCommand.java
index cc74c10ea4..6a319d9a25 100644
--- a/src/main/java/seedu/duke/command/ExitCommand.java
+++ b/src/main/java/seedu/duke/command/ExitCommand.java
@@ -4,8 +4,8 @@
import seedu.duke.ui.Ui;
public class ExitCommand extends Command{
- protected static boolean isExit = false;
public static final String COMMAND_WORD = "bye";
+ protected static boolean isExit = false;
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index a5d49af85b..345ad48895 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -24,26 +24,27 @@ public class Parser {
* @return the command based on the user input
*/
public static Command parseCommand(Menu menu, String userInput) {
- String command[] = userInput.split(" ");
+ String[] command = userInput.split(" ");
switch (command[0].toLowerCase()) {
- case ListMenuCommand.COMMAND_WORD:
- return new ListMenuCommand();
- /*case ListIngredientCommand.COMMAND_WORD:
- return prepareListIngredient(menu,userInput);
- case DeleteDishCommand.COMMAND_WORD:
- return prepareDelete(menu,userInput);*/
- case ExitCommand.COMMAND_WORD:
- return new ExitCommand();
- case AddDishCommand.COMMAND_WORD:
- //return new AddDishCommand();
- return new IncorrectCommand("DEXTER DO WORK");
- default:
- return new IncorrectCommand("Whoa there, tiger! Your command has left me scratching my virtual head. Let's try that again, shall we?");
+ case ListMenuCommand.COMMAND_WORD:
+ return new ListMenuCommand();
+ /*case ListIngredientCommand.COMMAND_WORD:
+ return prepareListIngredient(menu,userInput);
+ case DeleteDishCommand.COMMAND_WORD:
+ return prepareDelete(menu,userInput);*/
+ case ExitCommand.COMMAND_WORD:
+ return new ExitCommand();
+ case AddDishCommand.COMMAND_WORD:
+ //return new AddDishCommand();
+ return new IncorrectCommand("DEXTER DO WORK");
+ default:
+ return new IncorrectCommand("Your command has left me scratching my virtual head. " +
+ "Let's try that again, shall we?");
}
}
/**
- *
+ * Parses arguments in the context of the ListIngredient command.
* @param menu
* @param userInput
* @return the prepared command
@@ -82,7 +83,8 @@ private static Command prepareDelete(Menu menu, String userInput) {
* @throws ParseException if no region of the args string could be found for the index
* @throws NumberFormatException the args string region is not a valid number
*/
- private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command) throws ParseException, NumberFormatException {
+ private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command)
+ throws ParseException, NumberFormatException {
String formattedString = userInput.replace(command, "").trim();
int listIndex = Integer.parseInt(formattedString);
return listIndex;
From eed8da07c304064b6e444c35e284ab8e0c393455 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 02:58:57 +0800
Subject: [PATCH 053/870] Update code based on gradle coding standard
---
src/test/java/seedu/duke/command/AddDishCommandTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/test/java/seedu/duke/command/AddDishCommandTest.java b/src/test/java/seedu/duke/command/AddDishCommandTest.java
index 7a6fbc170f..080d872634 100644
--- a/src/test/java/seedu/duke/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/duke/command/AddDishCommandTest.java
@@ -8,7 +8,7 @@
import java.util.ArrayList;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
class AddDishCommandTest {
@Test
@@ -20,7 +20,7 @@ void execute_dishAdded_expectDishInMenu() {
//creating a dish
ingredients.add(new Ingredient("chicken", "100g"));
Dish dish = new Dish("Chicken Rice", ingredients, (float) 1.00);
-
+
AddDishCommand addDishCommand = new AddDishCommand(dish);
addDishCommand.execute(menu, ui);
From 71629404bad7b6184f37a4cff09948061ab74dda Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 03:00:43 +0800
Subject: [PATCH 054/870] Update ListMenuCommandTest.java
---
src/test/java/seedu/duke/command/ListMenuCommandTest.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/test/java/seedu/duke/command/ListMenuCommandTest.java b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
index 8e517c173a..efdeec53b1 100644
--- a/src/test/java/seedu/duke/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
@@ -9,13 +9,13 @@
class ListMenuCommandTest {
@Test
- public static void execute_outputTwoDishes_() {
+ public static void execute_expectTwoDishes() {
ArrayList menuItems = new ArrayList<>();
menuItems.add(new Dish("Chicken Rice", 2.50F));
menuItems.add(new Dish("Chicken Curry", 4.30F));
Menu menu = new Menu(menuItems);
- Command ListMenuCommand = new ListMenuCommand();
- ListMenuCommand.execute(menu, new Ui());
+ Command listMenuCommand = new ListMenuCommand();
+ listMenuCommand.execute(menu, new Ui());
}
}
From ec3ad41cac129fdce30e4415477e1dded5257571 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 03:05:40 +0800
Subject: [PATCH 055/870] Update Duke.java
---
src/main/java/seedu/duke/Duke.java | 40 ++++++++----------------------
1 file changed, 11 insertions(+), 29 deletions(-)
diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java
index a37649b497..96a3abfd3f 100644
--- a/src/main/java/seedu/duke/Duke.java
+++ b/src/main/java/seedu/duke/Duke.java
@@ -1,36 +1,18 @@
package seedu.duke;
-import seedu.duke.command.Command;
-import seedu.duke.data.Menu;
-import seedu.duke.parser.Parser;
-import seedu.duke.ui.Ui;
-import seedu.duke.command.ExitCommand;
+import java.util.Scanner;
public class Duke {
- /**
- * Main entry-point for the java.duke.Duke application.
- */
- private Ui ui;
- private Menu menu;
public static void main(String[] args) {
- new Duke().run();
- }
-
- /** Runs the program until termination. */
- public void run() {
- runCommandLoopUntilExitCommand();
- exit(ui);
- }
- /** Reads the user command and executes it, until the user issues the exit command. */
- public void runCommandLoopUntilExitCommand() {
- do {
- String item = ui.receiveUserInput();
- Command c = Parser.parseCommand(menu, item);
- c.execute(menu, ui);
- } while (!ExitCommand.isExit());
- }
- private static void exit(Ui ui) {
- ui.showGoodbye();
- System.exit(0);
+ String logo = " ____ _ \n"
+ + "| _ \\ _ _| | _____ \n"
+ + "| | | | | | | |/ / _ \\\n"
+ + "| |_| | |_| | < __/\n"
+ + "|____/ \\__,_|_|\\_\\___|\n";
+ System.out.println("Hello from\n" + logo);
+ System.out.println("What is your name?");
+ Scanner in = new Scanner(System.in);
+ System.out.println("Hello " + in.nextLine());
}
}
+
From 108544c2ee7ab0add14e4add818cec3bd9833423 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 03:11:59 +0800
Subject: [PATCH 056/870] Update code with regards to Gradle
---
src/main/java/seedu/duke/Duke.java | 39 +++++--------------
.../seedu/duke/command/AddDishCommand.java | 2 +-
.../java/seedu/duke/command/ExitCommand.java | 2 +-
src/main/java/seedu/duke/parser/Parser.java | 33 +++++++++-------
.../duke/command/ListMenuCommandTest.java | 6 +--
5 files changed, 32 insertions(+), 50 deletions(-)
diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java
index 87b920c350..4a3b06f389 100644
--- a/src/main/java/seedu/duke/Duke.java
+++ b/src/main/java/seedu/duke/Duke.java
@@ -1,38 +1,17 @@
package seedu.duke;
-import seedu.duke.command.Command;
-import seedu.duke.data.Menu;
-import seedu.duke.parser.Parser;
-import seedu.duke.ui.Ui;
-import seedu.duke.command.ExitCommand;
-
import java.util.Scanner;
public class Duke {
- /**
- * Main entry-point for the java.duke.Duke application.
- */
- private Ui ui;
- private Menu menu;
public static void main(String[] args) {
- new Duke().run();
- }
-
- /** Runs the program until termination. */
- public void run() {
- runCommandLoopUntilExitCommand();
- exit(ui);
- }
- /** Reads the user command and executes it, until the user issues the exit command. */
- public void runCommandLoopUntilExitCommand() {
- do {
- String item = ui.receiveUserInput();
- Command c = Parser.parseCommand(menu, item);
- c.execute(menu, ui);
- } while (!ExitCommand.isExit());
- }
- private static void exit(Ui ui) {
- ui.showGoodbye();
- System.exit(0);
+ String logo = " ____ _ \n"
+ + "| _ \\ _ _| | _____ \n"
+ + "| | | | | | | |/ / _ \\\n"
+ + "| |_| | |_| | < __/\n"
+ + "|____/ \\__,_|_|\\_\\___|\n";
+ System.out.println("Hello from\n" + logo);
+ System.out.println("What is your name?");
+ Scanner in = new Scanner(System.in);
+ System.out.println("Hello " + in.nextLine());
}
}
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
index 0fee423b6c..f256d9516f 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -8,8 +8,8 @@
* Adds a menu item to the user
*/
public class AddDishCommand extends Command {
- Dish dish;
public static final String COMMAND_WORD = "add";
+ Dish dish;
public AddDishCommand(Dish dish) {
this.dish = dish;
}
diff --git a/src/main/java/seedu/duke/command/ExitCommand.java b/src/main/java/seedu/duke/command/ExitCommand.java
index cc74c10ea4..6a319d9a25 100644
--- a/src/main/java/seedu/duke/command/ExitCommand.java
+++ b/src/main/java/seedu/duke/command/ExitCommand.java
@@ -4,8 +4,8 @@
import seedu.duke.ui.Ui;
public class ExitCommand extends Command{
- protected static boolean isExit = false;
public static final String COMMAND_WORD = "bye";
+ protected static boolean isExit = false;
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 703f2f1586..345ad48895 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -24,25 +24,27 @@ public class Parser {
* @return the command based on the user input
*/
public static Command parseCommand(Menu menu, String userInput) {
- String command[] = userInput.split(" ");
+ String[] command = userInput.split(" ");
switch (command[0].toLowerCase()) {
- case ListMenuCommand.COMMAND_WORD:
- return new ListMenuCommand();
- /*case ListIngredientCommand.COMMAND_WORD:
- return prepareListIngredient(menu,userInput);
- case DeleteDishCommand.COMMAND_WORD:
- return prepareDelete(menu,userInput);*/
- case ExitCommand.COMMAND_WORD:
- return new ExitCommand();
- case AddDishCommand.COMMAND_WORD:
- return new AddDishCommand();
- default:
- return new IncorrectCommand("Whoa there, tiger! Your command has left me scratching my virtual head. Let's try that again, shall we?");
+ case ListMenuCommand.COMMAND_WORD:
+ return new ListMenuCommand();
+ /*case ListIngredientCommand.COMMAND_WORD:
+ return prepareListIngredient(menu,userInput);
+ case DeleteDishCommand.COMMAND_WORD:
+ return prepareDelete(menu,userInput);*/
+ case ExitCommand.COMMAND_WORD:
+ return new ExitCommand();
+ case AddDishCommand.COMMAND_WORD:
+ //return new AddDishCommand();
+ return new IncorrectCommand("DEXTER DO WORK");
+ default:
+ return new IncorrectCommand("Your command has left me scratching my virtual head. " +
+ "Let's try that again, shall we?");
}
}
/**
- *
+ * Parses arguments in the context of the ListIngredient command.
* @param menu
* @param userInput
* @return the prepared command
@@ -81,7 +83,8 @@ private static Command prepareDelete(Menu menu, String userInput) {
* @throws ParseException if no region of the args string could be found for the index
* @throws NumberFormatException the args string region is not a valid number
*/
- private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command) throws ParseException, NumberFormatException {
+ private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command)
+ throws ParseException, NumberFormatException {
String formattedString = userInput.replace(command, "").trim();
int listIndex = Integer.parseInt(formattedString);
return listIndex;
diff --git a/src/test/java/seedu/duke/command/ListMenuCommandTest.java b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
index 8e517c173a..efdeec53b1 100644
--- a/src/test/java/seedu/duke/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/duke/command/ListMenuCommandTest.java
@@ -9,13 +9,13 @@
class ListMenuCommandTest {
@Test
- public static void execute_outputTwoDishes_() {
+ public static void execute_expectTwoDishes() {
ArrayList menuItems = new ArrayList<>();
menuItems.add(new Dish("Chicken Rice", 2.50F));
menuItems.add(new Dish("Chicken Curry", 4.30F));
Menu menu = new Menu(menuItems);
- Command ListMenuCommand = new ListMenuCommand();
- ListMenuCommand.execute(menu, new Ui());
+ Command listMenuCommand = new ListMenuCommand();
+ listMenuCommand.execute(menu, new Ui());
}
}
From c88d9091f99c7c1c13c815b1a926dec91d729117 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 11:02:43 +0800
Subject: [PATCH 057/870] Parser.java: add parserCommand() method and
incomplete prepareEditPriceCommand()
---
.../seedu/duke/command/EditPriceCommand.java | 1 +
src/main/java/seedu/duke/parser/Parser.java | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/src/main/java/seedu/duke/command/EditPriceCommand.java b/src/main/java/seedu/duke/command/EditPriceCommand.java
index 766ca15fce..461d2029b5 100644
--- a/src/main/java/seedu/duke/command/EditPriceCommand.java
+++ b/src/main/java/seedu/duke/command/EditPriceCommand.java
@@ -7,6 +7,7 @@
* Edit the price of a dish of a certain index
*/
public class EditPriceCommand extends Command {
+ public static final String COMMAND_WORD = "edit price";
private final int menuID;
private final float newPrice;
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index e23fe0ca92..25292f7296 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -1,9 +1,28 @@
package seedu.duke.parser;
+import seedu.duke.command.Command;
+import seedu.duke.command.EditPriceCommand;
+
/**
* Parse everything received from the users on terminal
* into a format that can be interpreted by other core classes
*/
public class Parser {
+ public Command parseCommand(String userInput) {
+ String[] command = userInput.trim().split(" ");
+
+ switch (command[0].toLowerCase()) {
+ case EditPriceCommand.COMMAND_WORD:
+ return prepareEditPriceCommand();
+ }
+ }
+
+ private Command prepareEditPriceCommand() {
+ try {
+ final int dishIndex = parseArgsAsDisplayedIndex(userInput);
+ return new EditPriceCommand(dishIndex, price);
+ }
+ }
+
}
From 38e05b78ff2369a7299c9de1a6c53cfa8560537d Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 12:25:39 +0800
Subject: [PATCH 058/870] Add constant COMMAND_WORD in executable command
classes
---
src/main/java/seedu/duke/command/AddDishCommand.java | 2 ++
src/main/java/seedu/duke/command/DeleteDishCommand.java | 2 ++
src/main/java/seedu/duke/command/ListIngredientCommand.java | 2 ++
src/main/java/seedu/duke/command/ListMenuCommand.java | 2 ++
4 files changed, 8 insertions(+)
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/duke/command/AddDishCommand.java
index 4ac249c333..256bf0a279 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/duke/command/AddDishCommand.java
@@ -7,6 +7,8 @@
* Adds a menu item to the user
*/
public class AddDishCommand extends Command{
+ public static final String COMMAND_WORD = "add";
+
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index fe3932cbaa..e911e0d667 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -8,6 +8,8 @@
*/
public class DeleteDishCommand extends Command {
+ public static final String COMMAND_WORD = "delete";
+
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 1941f878bb..9f902bc303 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -7,6 +7,8 @@
* Lists all ingredients used in the selected dish to the user.
*/
public class ListIngredientCommand extends Command{
+ public static final String COMMAND_WORD = "list ingredients";
+
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/duke/command/ListMenuCommand.java
index 12a8f57d4c..03c7364436 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/duke/command/ListMenuCommand.java
@@ -8,6 +8,8 @@
* Lists all dishes in the menu to the user.
*/
public class ListMenuCommand extends Command {
+ public static final String COMMAND_WORD = "list menu";
+
@Override
public void execute(Menu menu, Ui ui) {
/*for (String d : menu) {
From 2743a171159dc3e00cc9bf9134802df91516a91c Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 12:29:17 +0800
Subject: [PATCH 059/870] Declare COMMAND_ARGUMENT_STRING for compiling
patterns
---
src/main/java/seedu/duke/parser/Parser.java | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 882eec6db4..73366c20b5 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -3,7 +3,12 @@
import seedu.duke.command.Command;
import seedu.duke.command.ListIngredientCommand;
import seedu.duke.command.ListMenuCommand;
+import seedu.duke.command.AddDishCommand;
+import seedu.duke.command.DeleteDishCommand;
+import seedu.duke.command.IncorrectCommand;
+import javax.swing.*;
+import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -12,14 +17,13 @@
* into a format that can be interpreted by other core classes
*/
public class Parser {
- public static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?\\S+)(?.*)");
- final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim());
- if (!matcher.matches()) {
- return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
- }
+ public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
- final String commandWord = matcher.group("commandWord");
- final String arguments = matcher.group("arguments");
+ // Command Argument Patterns
+ private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z]+) price/(\\d+(\\.\\d+)?) (ingredient/[A-Za-z]+ qty/(\\d+(\\.\\d+)?)(?:, )?)+";
+ private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
+ private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
+ private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
public Command parseCommand(String userInput) {
switch (commandWord) {
From fc0ae7663b7c245853f11061b2d7d0531b378f6c Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 12:30:22 +0800
Subject: [PATCH 060/870] Implement parseCommand with pattern and matcher
---
src/main/java/seedu/duke/parser/Parser.java | 32 +++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 73366c20b5..9a2acc9698 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -25,11 +25,39 @@ public class Parser {
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
+ /**
+ * Parse userInput and group it under commandWord and arguments
+ * use commandWord to find the matching command and prepare the command
+ * @param userInput full user input
+ * @return command requested by the user
+ */
public Command parseCommand(String userInput) {
+ final Matcher matcher = COMMAND_ARGUMENT_FORMAT.matcher(userInput.trim());
+ if (!matcher.matches()) {
+ return new IncorrectCommand("Incorrect command format!");
+ }
+
+ final String commandWord = matcher.group("commandWord");
+ final String arguments = matcher.group("arguments");
+
switch (commandWord) {
- case AddDishCommand.COMMAND_WORD:
- return prepareAdd(arguments);
+ case AddDishCommand.COMMAND_WORD:
+ return prepareAdd(arguments);
+
+ case DeleteDishCommand.COMMAND_WORD:
+ return prepareDelete(arguments);
+
+ case ListIngredientCommand.COMMAND_WORD:
+ return prepareListIngredient(arguments);
+
+ case ListMenuCommand.COMMAND_WORD:
+ return prepareListMenu();
+
+ default:
+ return new IncorrectCommand("Incorrect command format!");
+ }
+ }
case DeleteDishCommand.COMMAND_WORD:
return prepareDelete(arguments);
From 87643e1fff76ea1ff58a72c59069501ea1ad8d5d Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 12:31:00 +0800
Subject: [PATCH 061/870] Parser.java: design the overall structure of
different prepareCommands
---
src/main/java/seedu/duke/parser/Parser.java | 64 +++++++++++++++++----
1 file changed, 54 insertions(+), 10 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 9a2acc9698..0a0510c6c7 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -59,20 +59,64 @@ public Command parseCommand(String userInput) {
}
}
- case DeleteDishCommand.COMMAND_WORD:
- return prepareDelete(arguments);
+ private Command prepareListMenu() {
+ // To be implemented by xx
+ return null;
+ }
+
+ private Command prepareListIngredient(String arguments) {
+ // To be implemented by xx
+ return null;
+ }
- case EditPriceCommand.COMMAND_WORD:
- return new ClearCommand();
+ private Command prepareDelete(String arguments) {
+ // To be implemented by xx
+ return null;
+ }
- case ListIngredientCommand.COMMAND_WORD:
- return prepareFind(arguments);
+ private Command prepareAdd(String arguments) {
+ final Pattern ADD_ARGUMENT_PATTERN = Pattern.compile(ADD_ARGUMENT_STRING);
+ Matcher matcher = ADD_ARGUMENT_PATTERN.matcher(arguments);
- case ListMenuCommand.COMMAND_WORD:
- return new ListCommand();
+ // Checks whether the overall pattern of add arguments is correct
+ if (matcher.matches()) {
+ return new IncorrectCommand("Error: Missing arguments for the add command.");
+ }
- default:
- return new HelpCommand();
+ try {
+ // To retrieve specific arguments from arguments
+ String dishName = matcher.group(1);
+ float price = Float.parseFloat(matcher.group(2));
+
+ // Capture the list of ingredients and quantities
+ ArrayList ingredients = new ArrayList<>();
+ ArrayList quantities = new ArrayList<>();
+
+ // Find all matches for ingredients and quantities
+ Pattern ingredientPattern = Pattern.compile("ingredient/([A-Za-z]+) qty/([A-Za-z]+)");
+ Matcher ingredientMatcher = ingredientPattern.matcher(arguments);
+
+ while (ingredientMatcher.find()) {
+ String ingredient = ingredientMatcher.group(1);
+ String quantity = ingredientMatcher.group(2);
+ ingredients.add(ingredient);
+ quantities.add(quantity);
+ }
+
+ // Todo: Implement error handling for checking the size of ingredients quantities
+ // I am not sure if this is necessary as we have already checked
+ // the overall command pattern in line 62
+
+ // Todo: Add the attributes in AddDishCommand
+ // Todo: Overload the constructor of Dish such that
+ // it can take in ingredients list and quantities list
+ // and create an arrayList of ingredient objects
+ // return new AddDishCommand(dishName, price, ingredients, quantities);
+ } catch (Exception e) {
+ // Todo: Add error handling for invalid price type etc.
}
+
+ return new IncorrectCommand("The specific details are " +
+ "to be implemented by Dexter");
}
}
From 5e69f2317cb5536d4b0bbad556082b7c831439a8 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 14:26:03 +0800
Subject: [PATCH 062/870] Rename remove to removeDish method
---
src/main/java/seedu/duke/command/DeleteDishCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index 48fea6ab9d..a5e7320745 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -21,7 +21,7 @@ public DeleteDishCommand(int index) {
@Override
public void execute(Menu menu, Ui ui) {
- menu.remove(dishIndex);
+ menu.removeDish(dishIndex);
ui.showDeleteMessage(menu.getDish(dishIndex).toString());
};
}
From be50d359eeb512d129d052773bddfd07c2982b9f Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 15:09:47 +0800
Subject: [PATCH 063/870] Handle invalid index error
---
.../seedu/duke/command/DeleteDishCommand.java | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index 01e0fcaf86..144f443632 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -1,6 +1,8 @@
package seedu.duke.command;
import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
+import seedu.duke.data.dish.Ingredient;
import seedu.duke.ui.Ui;
/**
@@ -14,20 +16,23 @@ public class DeleteDishCommand extends Command {
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
- private int dishIndex;
-
/**
* Constructor for DeleteDishCommand
*
* @param index index of menu item to be deleted
*/
public DeleteDishCommand(int index) {
- this.dishIndex = index;
+ this.index = index;
}
@Override
public void execute(Menu menu, Ui ui) {
- menu.removeDish(dishIndex);
- ui.showDeleteMessage(menu.getDish(dishIndex).toString());
+ Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
+ if (selectedDish != null) {
+ ui.showDeleteMessage(selectedDish);
+ } else {
+ ui.showToUser("Please select a valid dish index :)");
+ }
+ menu.removeDish(index);
}
}
From 411253bc7049f64567ed3785d19fc9e8d93c4dbb Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 15:10:27 +0800
Subject: [PATCH 064/870] Reformat printed string
---
src/main/java/seedu/duke/ui/Ui.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index d6be50e9a6..5e8d546e2f 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -73,10 +73,10 @@ public void printAddDishMessage(Dish dish) {
/**
* Shows delete message to user
*
- * @param menuItem String of menu item deleted
+ * @param selectedDish Dish to be deleted
*/
- public void showDeleteMessage(String menuItem) {
- showToUser("Okay! " + menuItem + " is deleted! :)");
+ public void showDeleteMessage(Dish selectedDish) {
+ showToUser("Okay! " + selectedDish.getName() + " is deleted! :)");
}
From 517bdf262e8a206ffde596e42f4ce95e17ea3d1f Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Tue, 17 Oct 2023 15:10:33 +0800
Subject: [PATCH 065/870] Implement parsing for listing ingredients and
necessary error handling.
Fixes #23
---
.../duke/command/ListIngredientCommand.java | 18 +++++++++++---
src/main/java/seedu/duke/parser/Parser.java | 24 ++++++++-----------
src/main/java/seedu/duke/ui/Ui.java | 18 +++++---------
3 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 0beee5c17b..675cf13253 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -1,19 +1,31 @@
package seedu.duke.command;
import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
+import seedu.duke.data.dish.Ingredient;
import seedu.duke.ui.Ui;
/**
* Lists all ingredients used in the selected dish to the user.
*/
-public class ListIngredientCommand extends Command{
+public class ListIngredientCommand extends Command {
public static final String COMMAND_WORD = "list_ingredients";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Lists out the ingredients needed along with the quantity for a specific dish.\n"
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
+
+ public ListIngredientCommand(int listIndex){
+ this.index = listIndex;
+ }
+
@Override
public void execute(Menu menu, Ui ui) {
- ui.printIngredients(menu, index);
- };
+ Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
+ if (selectedDish != null) {
+ ui.printIngredients(selectedDish);
+ } else {
+ ui.showToUser("Please select a valid dish index :)");
+ }
+ }
}
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 345ad48895..a16a388c93 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -28,9 +28,9 @@ public static Command parseCommand(Menu menu, String userInput) {
switch (command[0].toLowerCase()) {
case ListMenuCommand.COMMAND_WORD:
return new ListMenuCommand();
- /*case ListIngredientCommand.COMMAND_WORD:
- return prepareListIngredient(menu,userInput);
- case DeleteDishCommand.COMMAND_WORD:
+ case ListIngredientCommand.COMMAND_WORD:
+ return prepareListIngredient(userInput);
+ /*case DeleteDishCommand.COMMAND_WORD:
return prepareDelete(menu,userInput);*/
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
@@ -45,15 +45,13 @@ public static Command parseCommand(Menu menu, String userInput) {
/**
* Parses arguments in the context of the ListIngredient command.
- * @param menu
- * @param userInput
+ * @param userInput arguments string to parse as index number
* @return the prepared command
*/
- private static Command prepareListIngredient(Menu menu, String userInput) {
+ private static Command prepareListIngredient(String userInput) {
try {
- final int listIndex = parseArgsAsDisplayedIndex(menu ,userInput, ListIngredientCommand.COMMAND_WORD);
- //return new ListIngredientCommand(Menu menu, listIndex);
- return new IncorrectCommand("NAYCHI DO YOUR WORK");
+ final int listIndex = parseArgsAsDisplayedIndex(userInput, ListIngredientCommand.COMMAND_WORD);
+ return new ListIngredientCommand(listIndex);
} catch (ParseException e) {
return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + ListIngredientCommand.MESSAGE_USAGE);
} catch (NumberFormatException nfe) {
@@ -63,7 +61,7 @@ private static Command prepareListIngredient(Menu menu, String userInput) {
private static Command prepareDelete(Menu menu, String userInput) {
try {
- final int listIndex = parseArgsAsDisplayedIndex(menu, userInput, DeleteDishCommand.COMMAND_WORD);
+ final int listIndex = parseArgsAsDisplayedIndex(userInput, DeleteDishCommand.COMMAND_WORD);
//return new DeleteDishCommand(listIndex);
return new IncorrectCommand("SHANICE DO YOUR WORK");
} catch (ParseException e) {
@@ -78,15 +76,13 @@ private static Command prepareDelete(Menu menu, String userInput) {
*
* @param userInput arguments string to parse as index number
* @param command expected String name of the command called
- * @param menu The arraylist object created that stores current dishes
* @return the parsed index number
* @throws ParseException if no region of the args string could be found for the index
* @throws NumberFormatException the args string region is not a valid number
*/
- private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command)
+ private static int parseArgsAsDisplayedIndex(String userInput, String command)
throws ParseException, NumberFormatException {
String formattedString = userInput.replace(command, "").trim();
- int listIndex = Integer.parseInt(formattedString);
- return listIndex;
+ return Integer.parseInt(formattedString);
}
}
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 96554c4e2e..8b5a7de6cb 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -33,19 +33,13 @@ public void showGoodbye() {
* Prints out the quantity of each ingredient needed for the
* dish that the user selects.
*
- * @param menu The list of menu items.
- * @param dishIndex The index of the dish whose ingredients need to be printed.
+ * @param selectedDish Dish for ingredients to be listed out.
*/
- public void printIngredients(Menu menu, int dishIndex) {
- Dish selectedDish = menu.getMenuItemsList().get(dishIndex - 1);
- if (selectedDish != null) {
- showToUser(selectedDish.getName() + " Ingredients: \n");
-
- for (Ingredient ingredient : selectedDish.getIngredients()) {
- showToUser(ingredient.getName() + " - " + ingredient.getQuantity());
- }
- } else {
- showToUser("Please select a valid dish index :)");
+ public void printIngredients(Dish selectedDish) {
+ showToUser(selectedDish.getName() + " Ingredients: \n");
+
+ for (Ingredient ingredient : selectedDish.getIngredients()) {
+ showToUser(ingredient.getName() + " - " + ingredient.getQuantity());
}
}
From 2e861f26e20a182639268add85bec7b82792038c Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 15:10:58 +0800
Subject: [PATCH 066/870] Fixes #22
Implement parser support for deleting a dish
---
src/main/java/seedu/duke/parser/Parser.java | 27 ++++++++++++---------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 345ad48895..34e44a2633 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -28,10 +28,10 @@ public static Command parseCommand(Menu menu, String userInput) {
switch (command[0].toLowerCase()) {
case ListMenuCommand.COMMAND_WORD:
return new ListMenuCommand();
- /*case ListIngredientCommand.COMMAND_WORD:
- return prepareListIngredient(menu,userInput);
+// case ListIngredientCommand.COMMAND_WORD:
+// return prepareListIngredient(menu,userInput);
case DeleteDishCommand.COMMAND_WORD:
- return prepareDelete(menu,userInput);*/
+ return prepareDelete(userInput);
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
case AddDishCommand.COMMAND_WORD:
@@ -51,7 +51,7 @@ public static Command parseCommand(Menu menu, String userInput) {
*/
private static Command prepareListIngredient(Menu menu, String userInput) {
try {
- final int listIndex = parseArgsAsDisplayedIndex(menu ,userInput, ListIngredientCommand.COMMAND_WORD);
+ final int listIndex = parseArgsAsDisplayedIndex(userInput, ListIngredientCommand.COMMAND_WORD);
//return new ListIngredientCommand(Menu menu, listIndex);
return new IncorrectCommand("NAYCHI DO YOUR WORK");
} catch (ParseException e) {
@@ -61,11 +61,16 @@ private static Command prepareListIngredient(Menu menu, String userInput) {
}
}
- private static Command prepareDelete(Menu menu, String userInput) {
+ /**
+ * Parses arguments in the context of the Delete command.
+ *
+ * @param userInput Input from the user
+ * @return Command to be executed
+ */
+ private static Command prepareDelete(String userInput) {
try {
- final int listIndex = parseArgsAsDisplayedIndex(menu, userInput, DeleteDishCommand.COMMAND_WORD);
- //return new DeleteDishCommand(listIndex);
- return new IncorrectCommand("SHANICE DO YOUR WORK");
+ final int listIndex = parseArgsAsDisplayedIndex(userInput, DeleteDishCommand.COMMAND_WORD);
+ return new DeleteDishCommand(listIndex);
} catch (ParseException e) {
return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE);
} catch (NumberFormatException nfe) {
@@ -78,15 +83,13 @@ private static Command prepareDelete(Menu menu, String userInput) {
*
* @param userInput arguments string to parse as index number
* @param command expected String name of the command called
- * @param menu The arraylist object created that stores current dishes
* @return the parsed index number
* @throws ParseException if no region of the args string could be found for the index
* @throws NumberFormatException the args string region is not a valid number
*/
- private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command)
+ private static int parseArgsAsDisplayedIndex(String userInput, String command)
throws ParseException, NumberFormatException {
String formattedString = userInput.replace(command, "").trim();
- int listIndex = Integer.parseInt(formattedString);
- return listIndex;
+ return Integer.parseInt(formattedString);
}
}
From 06da5aa5369ab28d0ad2880c2f68094700fb5cbe Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Tue, 17 Oct 2023 15:17:47 +0800
Subject: [PATCH 067/870] Remove unused imports from Ui class and
ListIngredientCommand class.
Fixes #23
---
src/main/java/seedu/duke/command/ListIngredientCommand.java | 1 -
src/main/java/seedu/duke/ui/Ui.java | 1 -
2 files changed, 2 deletions(-)
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 675cf13253..daa752ece8 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -2,7 +2,6 @@
import seedu.duke.data.Menu;
import seedu.duke.data.dish.Dish;
-import seedu.duke.data.dish.Ingredient;
import seedu.duke.ui.Ui;
/**
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 8b5a7de6cb..bbb54ed939 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -1,6 +1,5 @@
package seedu.duke.ui;
-import seedu.duke.data.Menu;
import seedu.duke.data.dish.Dish;
import seedu.duke.data.dish.Ingredient;
From e94d49fcda0fa69ee9d80bab03b075c94b7c80e5 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 15:18:50 +0800
Subject: [PATCH 068/870] Improve code standard
Fixes #22
---
src/main/java/seedu/duke/command/DeleteDishCommand.java | 1 -
src/main/java/seedu/duke/parser/Parser.java | 4 ++--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index 144f443632..265fb3ca46 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -2,7 +2,6 @@
import seedu.duke.data.Menu;
import seedu.duke.data.dish.Dish;
-import seedu.duke.data.dish.Ingredient;
import seedu.duke.ui.Ui;
/**
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 34e44a2633..a5309dbbb0 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -28,8 +28,8 @@ public static Command parseCommand(Menu menu, String userInput) {
switch (command[0].toLowerCase()) {
case ListMenuCommand.COMMAND_WORD:
return new ListMenuCommand();
-// case ListIngredientCommand.COMMAND_WORD:
-// return prepareListIngredient(menu,userInput);
+ //case ListIngredientCommand.COMMAND_WORD:
+ //return prepareListIngredient(menu,userInput);
case DeleteDishCommand.COMMAND_WORD:
return prepareDelete(userInput);
case ExitCommand.COMMAND_WORD:
From ea5dbbd520baf2c7ae4b0e34f21a81b974e40961 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Tue, 17 Oct 2023 16:59:57 +0800
Subject: [PATCH 069/870] Improve coding standard.
Fixes #23
---
src/main/java/seedu/duke/command/ListIngredientCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index daa752ece8..90ccca997f 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -14,7 +14,7 @@ public class ListIngredientCommand extends Command {
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
- public ListIngredientCommand(int listIndex){
+ public ListIngredientCommand(int listIndex) {
this.index = listIndex;
}
From 76f879d8556fefdcdd8426b7ce96f08e9661dcf8 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Tue, 17 Oct 2023 17:23:28 +0800
Subject: [PATCH 070/870] Parser.java: remove argument when creating
DeleteDishCommand and ListIngredientCommand
---
src/main/java/seedu/duke/parser/Parser.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 068916f26a..d54639ff16 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -55,7 +55,7 @@ public Command parseCommand(Menu menu, String userInput) {
return prepareDelete(arguments);
case ListIngredientCommand.COMMAND_WORD:
- return prepareListIngredient(arguments);
+ return prepareListIngredient();
case ListMenuCommand.COMMAND_WORD:
return prepareListMenu();
@@ -146,7 +146,7 @@ private static Command prepareListIngredient(String userInput) {
private static Command prepareDelete(String userInput) {
try {
final int listIndex = parseArgsAsDisplayedIndex(userInput, DeleteDishCommand.COMMAND_WORD);
- return new DeleteDishCommand(listIndex);
+ return new DeleteDishCommand();
} catch (ParseException e) {
return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE);
} catch (NumberFormatException nfe) {
From 3166afc463ac1cf0c36a3c0f02025286408336a9 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Tue, 17 Oct 2023 17:32:10 +0800
Subject: [PATCH 071/870] Parser.java: pass arguments to prepareListIngredient
---
src/main/java/seedu/duke/parser/Parser.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index d54639ff16..bfc27fd83b 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -55,7 +55,7 @@ public Command parseCommand(Menu menu, String userInput) {
return prepareDelete(arguments);
case ListIngredientCommand.COMMAND_WORD:
- return prepareListIngredient();
+ return prepareListIngredient(arguments);
case ListMenuCommand.COMMAND_WORD:
return prepareListMenu();
From 4e07571336b93f76098b442a3b7818cc3de7638f Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Tue, 17 Oct 2023 17:32:57 +0800
Subject: [PATCH 072/870] Update ListIngredientCommand.java with constructor
that takes in listIndex
---
src/main/java/seedu/duke/command/ListIngredientCommand.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 37e6e16962..90ccca997f 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -14,6 +14,10 @@ public class ListIngredientCommand extends Command {
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
+ public ListIngredientCommand(int listIndex) {
+ this.index = listIndex;
+ }
+
@Override
public void execute(Menu menu, Ui ui) {
Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
From 972c84e4f91f7e6184b2071370f7ce136e27da80 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Tue, 17 Oct 2023 17:48:58 +0800
Subject: [PATCH 073/870] Update Parser.java with correct coding standard
---
src/main/java/seedu/duke/parser/Parser.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index bfc27fd83b..a55c6a5ea0 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -4,7 +4,6 @@
import seedu.duke.command.Command;
import seedu.duke.command.AddDishCommand;
-import seedu.duke.command.Command;
import seedu.duke.command.DeleteDishCommand;
import seedu.duke.command.ExitCommand;
import seedu.duke.command.IncorrectCommand;
@@ -24,7 +23,8 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
// Command Argument Patterns
- private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z]+) price/(\\d+(\\.\\d+)?) (ingredient/[A-Za-z]+ qty/(\\d+(\\.\\d+)?)(?:, )?)+";
+ private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z]+) price/(\\d+(\\.\\d+)?)
+ (ingredient/[A-Za-z]+ qty/(\\d+(\\.\\d+)?)(?:, )?)+";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
@@ -121,7 +121,7 @@ private Command prepareAdd(String arguments) {
"to be implemented by Dexter");
}
- /**
+ /**
* Parses arguments in the context of the ListIngredient command.
* @param userInput arguments string to parse as index number
* @return the prepared command
From 17930caaedda6b70d54027eabb2b45b299f3429f Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Tue, 17 Oct 2023 17:52:11 +0800
Subject: [PATCH 074/870] Parser.java: split ADD_COMMAND_ARGUMENTS correctly
---
src/main/java/seedu/duke/parser/Parser.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index a55c6a5ea0..2c8d141142 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -23,8 +23,8 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
// Command Argument Patterns
- private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z]+) price/(\\d+(\\.\\d+)?)
- (ingredient/[A-Za-z]+ qty/(\\d+(\\.\\d+)?)(?:, )?)+";
+ private static final String ADD_PATTERN = "add name/(\\w+) price/(\\d+(\\.\\d+)?)" +
+ " (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
From 2f877b3b7908caaa0fa8feec1de4bf94936aa508 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Tue, 17 Oct 2023 17:54:35 +0800
Subject: [PATCH 075/870] Parser.java: update ADD_PATTERN to
ADD_ARGUMENT_PATTERN
---
src/main/java/seedu/duke/parser/Parser.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 2c8d141142..4ea3838798 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -23,7 +23,7 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
// Command Argument Patterns
- private static final String ADD_PATTERN = "add name/(\\w+) price/(\\d+(\\.\\d+)?)" +
+ private static final String ADD_ARGUMENT_STRING = "add name/(\\w+) price/(\\d+(\\.\\d+)?)" +
" (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
From fe4ae667b55c28acbef1156b7576731def556694 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Tue, 17 Oct 2023 17:58:46 +0800
Subject: [PATCH 076/870] Parser.java: correct indentation at line 129
---
src/main/java/seedu/duke/parser/Parser.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 4ea3838798..38ebf93198 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -121,11 +121,11 @@ private Command prepareAdd(String arguments) {
"to be implemented by Dexter");
}
- /**
- * Parses arguments in the context of the ListIngredient command.
- * @param userInput arguments string to parse as index number
- * @return the prepared command
- */
+ /**
+ * Parses arguments in the context of the ListIngredient command.
+ * @param userInput arguments string to parse as index number
+ * @return the prepared command
+ */
private static Command prepareListIngredient(String userInput) {
try {
final int listIndex = parseArgsAsDisplayedIndex(userInput, ListIngredientCommand.COMMAND_WORD);
From 59eef0cdf11d0ea66d95fb251b957f33a24b201f Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 18:09:21 +0800
Subject: [PATCH 077/870] Renamed main class to CafeCtrl
---
build.gradle | 4 ++--
.../command/AddDishCommand.java | 8 ++++----
.../{duke => cafectrl}/command/Command.java | 6 +++---
.../command/DeleteDishCommand.java | 8 ++++----
.../command/ExitCommand.java | 6 +++---
.../command/IncorrectCommand.java | 6 +++---
.../command/ListIngredientCommand.java | 8 ++++----
.../command/ListMenuCommand.java | 8 ++++----
.../seedu/{duke => cafectrl}/data/Menu.java | 8 ++++++--
.../{duke => cafectrl}/data/dish/Dish.java | 2 +-
.../data/dish/Ingredient.java | 2 +-
.../{duke => cafectrl}/parser/Parser.java | 18 +++++++++---------
.../java/seedu/{duke => cafectrl}/ui/Ui.java | 10 +++++++---
.../{duke => cafectrl}/ui/UserOutput.java | 2 +-
src/main/java/seedu/duke/Duke.java | 19 -------------------
.../seedu/{duke => cafectrl}/DukeTest.java | 2 +-
.../java/seedu/{duke => cafectrl}/UiTest.java | 2 +-
.../cafectrl/command/AddDishCommandTest.java | 5 +++++
.../seedu/cafectrl/command/CommandTest.java | 5 +++++
.../command/DeleteDishCommandTest.java | 2 +-
.../command/ListIngredientCommandTest.java | 2 +-
.../command/ListMenuCommandTest.java | 8 ++++----
.../{duke => cafectrl}/data/MenuTest.java | 2 +-
.../data/dish/DishTest.java | 2 +-
.../data/dish/IngredientTest.java | 2 +-
.../{duke => cafectrl}/parser/ParserTest.java | 2 +-
.../duke/command/AddDishCommandTest.java | 5 -----
.../java/seedu/duke/command/CommandTest.java | 5 -----
28 files changed, 74 insertions(+), 85 deletions(-)
rename src/main/java/seedu/{duke => cafectrl}/command/AddDishCommand.java (73%)
rename src/main/java/seedu/{duke => cafectrl}/command/Command.java (80%)
rename src/main/java/seedu/{duke => cafectrl}/command/DeleteDishCommand.java (88%)
rename src/main/java/seedu/{duke => cafectrl}/command/ExitCommand.java (76%)
rename src/main/java/seedu/{duke => cafectrl}/command/IncorrectCommand.java (80%)
rename src/main/java/seedu/{duke => cafectrl}/command/ListIngredientCommand.java (86%)
rename src/main/java/seedu/{duke => cafectrl}/command/ListMenuCommand.java (87%)
rename src/main/java/seedu/{duke => cafectrl}/data/Menu.java (80%)
rename src/main/java/seedu/{duke => cafectrl}/data/dish/Dish.java (95%)
rename src/main/java/seedu/{duke => cafectrl}/data/dish/Ingredient.java (93%)
rename src/main/java/seedu/{duke => cafectrl}/parser/Parser.java (89%)
rename src/main/java/seedu/{duke => cafectrl}/ui/Ui.java (91%)
rename src/main/java/seedu/{duke => cafectrl}/ui/UserOutput.java (94%)
delete mode 100644 src/main/java/seedu/duke/Duke.java
rename src/test/java/seedu/{duke => cafectrl}/DukeTest.java (88%)
rename src/test/java/seedu/{duke => cafectrl}/UiTest.java (71%)
create mode 100644 src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
create mode 100644 src/test/java/seedu/cafectrl/command/CommandTest.java
rename src/test/java/seedu/{duke => cafectrl}/command/DeleteDishCommandTest.java (51%)
rename src/test/java/seedu/{duke => cafectrl}/command/ListIngredientCommandTest.java (54%)
rename src/test/java/seedu/{duke => cafectrl}/command/ListMenuCommandTest.java (78%)
rename src/test/java/seedu/{duke => cafectrl}/data/MenuTest.java (71%)
rename src/test/java/seedu/{duke => cafectrl}/data/dish/DishTest.java (68%)
rename src/test/java/seedu/{duke => cafectrl}/data/dish/IngredientTest.java (70%)
rename src/test/java/seedu/{duke => cafectrl}/parser/ParserTest.java (66%)
delete mode 100644 src/test/java/seedu/duke/command/AddDishCommandTest.java
delete mode 100644 src/test/java/seedu/duke/command/CommandTest.java
diff --git a/build.gradle b/build.gradle
index ea82051fab..1dc381723f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -29,11 +29,11 @@ test {
}
application {
- mainClass.set("seedu.duke.Duke")
+ mainClass.set("seedu.cafectrl.CafeCtrl")
}
shadowJar {
- archiveBaseName.set("duke")
+ archiveBaseName.set("cafectrl")
archiveClassifier.set("")
}
diff --git a/src/main/java/seedu/duke/command/AddDishCommand.java b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
similarity index 73%
rename from src/main/java/seedu/duke/command/AddDishCommand.java
rename to src/main/java/seedu/cafectrl/command/AddDishCommand.java
index f256d9516f..b48e2f7e7e 100644
--- a/src/main/java/seedu/duke/command/AddDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
@@ -1,8 +1,8 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
-import seedu.duke.data.Menu;
-import seedu.duke.data.dish.Dish;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Ui;
/**
* Adds a menu item to the user
diff --git a/src/main/java/seedu/duke/command/Command.java b/src/main/java/seedu/cafectrl/command/Command.java
similarity index 80%
rename from src/main/java/seedu/duke/command/Command.java
rename to src/main/java/seedu/cafectrl/command/Command.java
index f2f7ccec9f..843159acd4 100644
--- a/src/main/java/seedu/duke/command/Command.java
+++ b/src/main/java/seedu/cafectrl/command/Command.java
@@ -1,7 +1,7 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
-import seedu.duke.data.Menu;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Ui;
/**
* Represents an executable command.
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
similarity index 88%
rename from src/main/java/seedu/duke/command/DeleteDishCommand.java
rename to src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
index 265fb3ca46..236ac412bf 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
@@ -1,8 +1,8 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
-import seedu.duke.data.Menu;
-import seedu.duke.data.dish.Dish;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Ui;
/**
* Deletes a menu item identified using it's last displayed index from the menu.
diff --git a/src/main/java/seedu/duke/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
similarity index 76%
rename from src/main/java/seedu/duke/command/ExitCommand.java
rename to src/main/java/seedu/cafectrl/command/ExitCommand.java
index 6a319d9a25..9279a39284 100644
--- a/src/main/java/seedu/duke/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -1,7 +1,7 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
-import seedu.duke.data.Menu;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Ui;
public class ExitCommand extends Command{
public static final String COMMAND_WORD = "bye";
diff --git a/src/main/java/seedu/duke/command/IncorrectCommand.java b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
similarity index 80%
rename from src/main/java/seedu/duke/command/IncorrectCommand.java
rename to src/main/java/seedu/cafectrl/command/IncorrectCommand.java
index e805d4dc12..e6ef7e9944 100644
--- a/src/main/java/seedu/duke/command/IncorrectCommand.java
+++ b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
@@ -1,7 +1,7 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
-import seedu.duke.data.Menu;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Ui;
/**
* Represents an incorrect command. Upon execution, produces some feedback to the user.
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
similarity index 86%
rename from src/main/java/seedu/duke/command/ListIngredientCommand.java
rename to src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
index 90ccca997f..ce7b989e6b 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
@@ -1,8 +1,8 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
-import seedu.duke.data.Menu;
-import seedu.duke.data.dish.Dish;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Ui;
/**
* Lists all ingredients used in the selected dish to the user.
diff --git a/src/main/java/seedu/duke/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
similarity index 87%
rename from src/main/java/seedu/duke/command/ListMenuCommand.java
rename to src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index 43ca95e4e2..5de86cb208 100644
--- a/src/main/java/seedu/duke/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -1,8 +1,8 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
-import seedu.duke.data.Menu;
-import seedu.duke.ui.Ui;
-import seedu.duke.ui.UserOutput;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Ui;
+import seedu.cafectrl.ui.UserOutput;
import java.text.DecimalFormat;
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/cafectrl/data/Menu.java
similarity index 80%
rename from src/main/java/seedu/duke/data/Menu.java
rename to src/main/java/seedu/cafectrl/data/Menu.java
index c1abd0b1ef..b841ca0e72 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/cafectrl/data/Menu.java
@@ -1,12 +1,16 @@
-package seedu.duke.data;
+package seedu.cafectrl.data;
-import seedu.duke.data.dish.Dish;
+import seedu.cafectrl.data.dish.Dish;
import java.util.ArrayList;
public class Menu {
private ArrayList menuItems;
+ public Menu() {
+ this.menuItems = new ArrayList<>();
+ }
+
public Menu(ArrayList menuItems) {
this.menuItems = menuItems;
}
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/cafectrl/data/dish/Dish.java
similarity index 95%
rename from src/main/java/seedu/duke/data/dish/Dish.java
rename to src/main/java/seedu/cafectrl/data/dish/Dish.java
index f188bc44ee..4b524842a6 100644
--- a/src/main/java/seedu/duke/data/dish/Dish.java
+++ b/src/main/java/seedu/cafectrl/data/dish/Dish.java
@@ -1,4 +1,4 @@
-package seedu.duke.data.dish;
+package seedu.cafectrl.data.dish;
import java.util.ArrayList;
diff --git a/src/main/java/seedu/duke/data/dish/Ingredient.java b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
similarity index 93%
rename from src/main/java/seedu/duke/data/dish/Ingredient.java
rename to src/main/java/seedu/cafectrl/data/dish/Ingredient.java
index e5e984fbf2..9fefb107eb 100644
--- a/src/main/java/seedu/duke/data/dish/Ingredient.java
+++ b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
@@ -1,4 +1,4 @@
-package seedu.duke.data.dish;
+package seedu.cafectrl.data.dish;
public class Ingredient {
private final String name;
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
similarity index 89%
rename from src/main/java/seedu/duke/parser/Parser.java
rename to src/main/java/seedu/cafectrl/parser/Parser.java
index 1307009dd2..cd0e78782c 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -1,13 +1,13 @@
-package seedu.duke.parser;
+package seedu.cafectrl.parser;
-import seedu.duke.command.AddDishCommand;
-import seedu.duke.command.Command;
-import seedu.duke.command.DeleteDishCommand;
-import seedu.duke.command.ExitCommand;
-import seedu.duke.command.IncorrectCommand;
-import seedu.duke.command.ListIngredientCommand;
-import seedu.duke.command.ListMenuCommand;
-import seedu.duke.data.Menu;
+import seedu.cafectrl.command.AddDishCommand;
+import seedu.cafectrl.command.Command;
+import seedu.cafectrl.command.DeleteDishCommand;
+import seedu.cafectrl.command.ExitCommand;
+import seedu.cafectrl.command.IncorrectCommand;
+import seedu.cafectrl.command.ListIngredientCommand;
+import seedu.cafectrl.command.ListMenuCommand;
+import seedu.cafectrl.data.Menu;
import java.text.ParseException;
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
similarity index 91%
rename from src/main/java/seedu/duke/ui/Ui.java
rename to src/main/java/seedu/cafectrl/ui/Ui.java
index 7b497f6a25..3d607040e8 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -1,7 +1,7 @@
-package seedu.duke.ui;
+package seedu.cafectrl.ui;
-import seedu.duke.data.dish.Dish;
-import seedu.duke.data.dish.Ingredient;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.data.dish.Ingredient;
import java.util.Scanner;
@@ -16,6 +16,10 @@ public Ui() {
scanner = new Scanner(System.in);
}
+ public void printLine() {
+ showToUser("-----------------------------------------------------");
+ }
+
public String receiveUserInput() {
return scanner.nextLine();
}
diff --git a/src/main/java/seedu/duke/ui/UserOutput.java b/src/main/java/seedu/cafectrl/ui/UserOutput.java
similarity index 94%
rename from src/main/java/seedu/duke/ui/UserOutput.java
rename to src/main/java/seedu/cafectrl/ui/UserOutput.java
index d29e9aa61d..8f31c08064 100644
--- a/src/main/java/seedu/duke/ui/UserOutput.java
+++ b/src/main/java/seedu/cafectrl/ui/UserOutput.java
@@ -1,4 +1,4 @@
-package seedu.duke.ui;
+package seedu.cafectrl.ui;
/**
* Enumerates messages to be displayed to users.
diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java
deleted file mode 100644
index 42f7853068..0000000000
--- a/src/main/java/seedu/duke/Duke.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package seedu.duke;
-
-import java.util.Scanner;
-
-public class Duke {
- public static void main(String[] args) {
- String logo = " ____ _ \n"
- + "| _ \\ _ _| | _____ \n"
- + "| | | | | | | |/ / _ \\\n"
- + "| |_| | |_| | < __/\n"
- + "|____/ \\__,_|_|\\_\\___|\n";
-
- System.out.println("Hello from\n" + logo);
- System.out.println("What is your name?");
- Scanner in = new Scanner(System.in);
- System.out.println("Hello " + in.nextLine());
- }
-}
-
diff --git a/src/test/java/seedu/duke/DukeTest.java b/src/test/java/seedu/cafectrl/DukeTest.java
similarity index 88%
rename from src/test/java/seedu/duke/DukeTest.java
rename to src/test/java/seedu/cafectrl/DukeTest.java
index 2dda5fd651..23f911598f 100644
--- a/src/test/java/seedu/duke/DukeTest.java
+++ b/src/test/java/seedu/cafectrl/DukeTest.java
@@ -1,4 +1,4 @@
-package seedu.duke;
+package seedu.cafectrl;
import static org.junit.jupiter.api.Assertions.assertTrue;
diff --git a/src/test/java/seedu/duke/UiTest.java b/src/test/java/seedu/cafectrl/UiTest.java
similarity index 71%
rename from src/test/java/seedu/duke/UiTest.java
rename to src/test/java/seedu/cafectrl/UiTest.java
index dccca8009f..ddf62b2fff 100644
--- a/src/test/java/seedu/duke/UiTest.java
+++ b/src/test/java/seedu/cafectrl/UiTest.java
@@ -1,4 +1,4 @@
-package seedu.duke;
+package seedu.cafectrl;
/**
diff --git a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
new file mode 100644
index 0000000000..ec5f75ec92
--- /dev/null
+++ b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
@@ -0,0 +1,5 @@
+package seedu.cafectrl.command;
+
+class AddDishCommandTest {
+
+}
diff --git a/src/test/java/seedu/cafectrl/command/CommandTest.java b/src/test/java/seedu/cafectrl/command/CommandTest.java
new file mode 100644
index 0000000000..0c92114477
--- /dev/null
+++ b/src/test/java/seedu/cafectrl/command/CommandTest.java
@@ -0,0 +1,5 @@
+package seedu.cafectrl.command;
+
+class CommandTest {
+
+}
diff --git a/src/test/java/seedu/duke/command/DeleteDishCommandTest.java b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
similarity index 51%
rename from src/test/java/seedu/duke/command/DeleteDishCommandTest.java
rename to src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
index b76f003c48..c6aca9c33c 100644
--- a/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
@@ -1,4 +1,4 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
class DeleteDishCommandTest {
diff --git a/src/test/java/seedu/duke/command/ListIngredientCommandTest.java b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
similarity index 54%
rename from src/test/java/seedu/duke/command/ListIngredientCommandTest.java
rename to src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
index 7247a13efb..15cacdf4cc 100644
--- a/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
@@ -1,4 +1,4 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
class ListIngredientCommandTest {
diff --git a/src/test/java/seedu/duke/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
similarity index 78%
rename from src/test/java/seedu/duke/command/ListMenuCommandTest.java
rename to src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index efdeec53b1..54222baaaf 100644
--- a/src/test/java/seedu/duke/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -1,9 +1,9 @@
-package seedu.duke.command;
+package seedu.cafectrl.command;
import org.junit.jupiter.api.Test;
-import seedu.duke.data.Menu;
-import seedu.duke.data.dish.Dish;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Ui;
import java.util.ArrayList;
diff --git a/src/test/java/seedu/duke/data/MenuTest.java b/src/test/java/seedu/cafectrl/data/MenuTest.java
similarity index 71%
rename from src/test/java/seedu/duke/data/MenuTest.java
rename to src/test/java/seedu/cafectrl/data/MenuTest.java
index 81e7db5e31..6d45579158 100644
--- a/src/test/java/seedu/duke/data/MenuTest.java
+++ b/src/test/java/seedu/cafectrl/data/MenuTest.java
@@ -1,4 +1,4 @@
-package seedu.duke.data;
+package seedu.cafectrl.data;
//import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/seedu/duke/data/dish/DishTest.java b/src/test/java/seedu/cafectrl/data/dish/DishTest.java
similarity index 68%
rename from src/test/java/seedu/duke/data/dish/DishTest.java
rename to src/test/java/seedu/cafectrl/data/dish/DishTest.java
index e315fb3f62..4fdb94bd3e 100644
--- a/src/test/java/seedu/duke/data/dish/DishTest.java
+++ b/src/test/java/seedu/cafectrl/data/dish/DishTest.java
@@ -1,4 +1,4 @@
-package seedu.duke.data.dish;
+package seedu.cafectrl.data.dish;
//import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/seedu/duke/data/dish/IngredientTest.java b/src/test/java/seedu/cafectrl/data/dish/IngredientTest.java
similarity index 70%
rename from src/test/java/seedu/duke/data/dish/IngredientTest.java
rename to src/test/java/seedu/cafectrl/data/dish/IngredientTest.java
index f3b5c160ac..4aac568907 100644
--- a/src/test/java/seedu/duke/data/dish/IngredientTest.java
+++ b/src/test/java/seedu/cafectrl/data/dish/IngredientTest.java
@@ -1,4 +1,4 @@
-package seedu.duke.data.dish;
+package seedu.cafectrl.data.dish;
//import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/seedu/duke/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
similarity index 66%
rename from src/test/java/seedu/duke/parser/ParserTest.java
rename to src/test/java/seedu/cafectrl/parser/ParserTest.java
index f9108f5a6e..56cc60f428 100644
--- a/src/test/java/seedu/duke/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -1,4 +1,4 @@
-package seedu.duke.parser;
+package seedu.cafectrl.parser;
/**
* Junit test for Parser.java
diff --git a/src/test/java/seedu/duke/command/AddDishCommandTest.java b/src/test/java/seedu/duke/command/AddDishCommandTest.java
deleted file mode 100644
index 70ef96c235..0000000000
--- a/src/test/java/seedu/duke/command/AddDishCommandTest.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package seedu.duke.command;
-
-class AddDishCommandTest {
-
-}
diff --git a/src/test/java/seedu/duke/command/CommandTest.java b/src/test/java/seedu/duke/command/CommandTest.java
deleted file mode 100644
index f63ea17f26..0000000000
--- a/src/test/java/seedu/duke/command/CommandTest.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package seedu.duke.command;
-
-class CommandTest {
-
-}
From 08b6d3757647c4100510c3f57df4a3423980a755 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 18:28:08 +0800
Subject: [PATCH 078/870] Edit main function to start CafeCtrl application
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 44 +++++++++++++++++++
.../seedu/cafectrl/command/ExitCommand.java | 11 ++---
text-ui-test/EXPECTED.TXT | 11 +----
3 files changed, 50 insertions(+), 16 deletions(-)
create mode 100644 src/main/java/seedu/cafectrl/CafeCtrl.java
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
new file mode 100644
index 0000000000..59d7839dfb
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -0,0 +1,44 @@
+package seedu.cafectrl;
+
+import seedu.cafectrl.command.Command;
+import seedu.cafectrl.command.ExitCommand;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.parser.Parser;
+import seedu.cafectrl.ui.Ui;
+
+public class CafeCtrl {
+ private final Ui ui;
+ private final Menu menu;
+ private Command command;
+
+ public CafeCtrl() {
+ ui = new Ui();
+ menu = new Menu();
+ }
+
+ private void setup() {
+ ui.showWelcome();
+ }
+
+ private void run() {
+ do {
+ try {
+ ui.printLine();
+ String fullUserInput = ui.receiveUserInput();
+ command = Parser.parseCommand(menu, fullUserInput);
+ command.execute(menu, ui);
+ } catch (Exception e) {
+ ui.showToUser(e.getMessage());
+ } finally {
+ ui.printLine();
+ }
+ } while (!(command instanceof ExitCommand)); //end the program if the command obj is a ExitCommand
+ }
+
+ public static void main(String[] args) {
+ CafeCtrl cafeCtrl = new CafeCtrl();
+ cafeCtrl.setup();
+ cafeCtrl.run();
+ }
+}
+
diff --git a/src/main/java/seedu/cafectrl/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
index 9279a39284..a46e9b7d37 100644
--- a/src/main/java/seedu/cafectrl/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -2,17 +2,14 @@
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.ui.Ui;
+import seedu.cafectrl.ui.UserOutput;
public class ExitCommand extends Command{
public static final String COMMAND_WORD = "bye";
- protected static boolean isExit = false;
-
@Override
public void execute(Menu menu, Ui ui) {
- isExit = true;
- }
-
- public static boolean isExit() {
- return isExit;
+ String msg = UserOutput.GOODBYE_MESSAGE.message;
+ ui.printLine();
+ ui.showToUser(msg);
}
}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 892cb6cae7..75f0764237 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,9 +1,2 @@
-Hello from
- ____ _
-| _ \ _ _| | _____
-| | | | | | | |/ / _ \
-| |_| | |_| | < __/
-|____/ \__,_|_|\_\___|
-
-What is your name?
-Hello James Gosling
+Hello! Welcome to CafeCTRL!
+-----------------------------------------------------
From 557ea9cc49cdf6bce167d8bba7f828c9bb35dfea Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 18:32:56 +0800
Subject: [PATCH 079/870] Add JavaDoc to appropriate methods
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
index 59d7839dfb..82d42aca51 100644
--- a/src/main/java/seedu/cafectrl/CafeCtrl.java
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -11,6 +11,9 @@ public class CafeCtrl {
private final Menu menu;
private Command command;
+ /**
+ * Private constructor for the CafeCtrl class, used for initializing the user interface and menu list.
+ */
public CafeCtrl() {
ui = new Ui();
menu = new Menu();
@@ -19,7 +22,13 @@ public CafeCtrl() {
private void setup() {
ui.showWelcome();
}
-
+
+ /**
+ * The main loop of the CafeCtrl application.
+ *
+ * This method consistently receives user input, parses commands, and executes the respective command
+ * until the user enters a "bye" command, terminating the application.
+ */
private void run() {
do {
try {
From 75c438d96f5dfbaaf0cef67a4c6f04bfc1d09eb9 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 18:59:44 +0800
Subject: [PATCH 080/870] Update test files
---
text-ui-test/EXPECTED.TXT | 3 +++
text-ui-test/input.txt | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 75f0764237..dc6f662650 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,2 +1,5 @@
Hello! Welcome to CafeCTRL!
-----------------------------------------------------
+-----------------------------------------------------
+Goodbye <3 Have a great day ahead!
+-----------------------------------------------------
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index f6ec2e9f95..b023018cab 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1 +1 @@
-James Gosling
\ No newline at end of file
+bye
From 87ceea9d298f8b648ed7219c550f363a2685ec60 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 20:25:07 +0800
Subject: [PATCH 081/870] Edit code to change displayed text
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 2 +-
src/main/java/seedu/cafectrl/command/ExitCommand.java | 3 +--
src/main/java/seedu/cafectrl/command/IncorrectCommand.java | 2 +-
src/main/java/seedu/cafectrl/ui/Ui.java | 1 +
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
index 82d42aca51..b6587ad14b 100644
--- a/src/main/java/seedu/cafectrl/CafeCtrl.java
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -30,9 +30,9 @@ private void setup() {
* until the user enters a "bye" command, terminating the application.
*/
private void run() {
+ ui.printLine();
do {
try {
- ui.printLine();
String fullUserInput = ui.receiveUserInput();
command = Parser.parseCommand(menu, fullUserInput);
command.execute(menu, ui);
diff --git a/src/main/java/seedu/cafectrl/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
index a46e9b7d37..9278497508 100644
--- a/src/main/java/seedu/cafectrl/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -8,8 +8,7 @@ public class ExitCommand extends Command{
public static final String COMMAND_WORD = "bye";
@Override
public void execute(Menu menu, Ui ui) {
- String msg = UserOutput.GOODBYE_MESSAGE.message;
ui.printLine();
- ui.showToUser(msg);
+ ui.showGoodbye();
}
}
diff --git a/src/main/java/seedu/cafectrl/command/IncorrectCommand.java b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
index e6ef7e9944..d9ba4f0fa9 100644
--- a/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
+++ b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
@@ -15,6 +15,6 @@ public IncorrectCommand(String feedbackToUser) {
@Override
public void execute(Menu menu, Ui ui) {
- //ui.showToUser(feedbackToUser);
+ ui.showToUser(feedbackToUser);
}
}
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 3d607040e8..5960b760a3 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -21,6 +21,7 @@ public void printLine() {
}
public String receiveUserInput() {
+ System.out.print("> ");
return scanner.nextLine();
}
From d96a43c56516085e4f47d119e887509154d76318 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 20:27:05 +0800
Subject: [PATCH 082/870] Remove unused import statement
---
src/main/java/seedu/cafectrl/command/ExitCommand.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
index 9278497508..ab50d30b98 100644
--- a/src/main/java/seedu/cafectrl/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -2,7 +2,6 @@
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.ui.Ui;
-import seedu.cafectrl.ui.UserOutput;
public class ExitCommand extends Command{
public static final String COMMAND_WORD = "bye";
From d98b3fe929b34eee9faaca7641a53998901fa68a Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 20:30:51 +0800
Subject: [PATCH 083/870] Update EXPECTED.TXT according to changes made
---
text-ui-test/EXPECTED.TXT | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index dc6f662650..983be930ab 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -1,5 +1,5 @@
Hello! Welcome to CafeCTRL!
-----------------------------------------------------
------------------------------------------------------
+> -----------------------------------------------------
Goodbye <3 Have a great day ahead!
-----------------------------------------------------
From ef8dd90e355a925a8d75c9a7ef0fd3e55e4efa46 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 21:55:10 +0800
Subject: [PATCH 084/870] Edit accessibility, add Javadoc and edit to resolve
coding standards
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 6 +++++-
src/main/java/seedu/cafectrl/command/ExitCommand.java | 2 +-
src/main/java/seedu/cafectrl/ui/Ui.java | 3 ++-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
index b6587ad14b..e476b2d0ad 100644
--- a/src/main/java/seedu/cafectrl/CafeCtrl.java
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -6,6 +6,10 @@
import seedu.cafectrl.parser.Parser;
import seedu.cafectrl.ui.Ui;
+/**
+ * CafeCtrl application's entry point.
+ * Initializes the application and starts the interaction with the user.
+ */
public class CafeCtrl {
private final Ui ui;
private final Menu menu;
@@ -14,7 +18,7 @@ public class CafeCtrl {
/**
* Private constructor for the CafeCtrl class, used for initializing the user interface and menu list.
*/
- public CafeCtrl() {
+ private CafeCtrl() {
ui = new Ui();
menu = new Menu();
}
diff --git a/src/main/java/seedu/cafectrl/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
index ab50d30b98..899e105ae7 100644
--- a/src/main/java/seedu/cafectrl/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -3,7 +3,7 @@
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.ui.Ui;
-public class ExitCommand extends Command{
+public class ExitCommand extends Command {
public static final String COMMAND_WORD = "bye";
@Override
public void execute(Menu menu, Ui ui) {
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 5960b760a3..f7ccd895f4 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -7,6 +7,7 @@
public class Ui {
public static final int OFFSET_LIST_INDEX = 1;
+ public static final String lineString = "-----------------------------------------------------";
private final Scanner scanner;
/**
@@ -17,7 +18,7 @@ public Ui() {
}
public void printLine() {
- showToUser("-----------------------------------------------------");
+ showToUser(lineString);
}
public String receiveUserInput() {
From 6da928e074d832fb7ec5d798d84fe03a2dfd4b3c Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 22:10:10 +0800
Subject: [PATCH 085/870] Edit code for exiting loop logic
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 2 +-
src/main/java/seedu/cafectrl/command/Command.java | 9 +++++++++
src/main/java/seedu/cafectrl/command/ExitCommand.java | 11 +++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
index e476b2d0ad..e1b6aad114 100644
--- a/src/main/java/seedu/cafectrl/CafeCtrl.java
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -45,7 +45,7 @@ private void run() {
} finally {
ui.printLine();
}
- } while (!(command instanceof ExitCommand)); //end the program if the command obj is a ExitCommand
+ } while (!command.isExit());
}
public static void main(String[] args) {
diff --git a/src/main/java/seedu/cafectrl/command/Command.java b/src/main/java/seedu/cafectrl/command/Command.java
index 843159acd4..aec67d413b 100644
--- a/src/main/java/seedu/cafectrl/command/Command.java
+++ b/src/main/java/seedu/cafectrl/command/Command.java
@@ -14,6 +14,15 @@ public void setIndex(int index) {
this.index = index;
}
+ /**
+ * check whether this command is an exit command (user input "bye")
+ *
+ * default returns false, this method will be overridden in ExitCommand
+ */
+ public boolean isExit() {
+ return false;
+ }
+
/**
* Executes the command and returns the result.
*/
diff --git a/src/main/java/seedu/cafectrl/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
index 899e105ae7..4cf2685ef7 100644
--- a/src/main/java/seedu/cafectrl/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -5,6 +5,17 @@
public class ExitCommand extends Command {
public static final String COMMAND_WORD = "bye";
+
+ /**
+ * Overrides the isExit() method which returns false
+ *
+ * @return true
+ */
+ @Override
+ public boolean isExit() {
+ return true;
+ }
+
@Override
public void execute(Menu menu, Ui ui) {
ui.printLine();
From 597bd744aa3a8af3f037200da66ec4124e067311 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Tue, 17 Oct 2023 22:14:28 +0800
Subject: [PATCH 086/870] Edit code to follow coding standards
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 1 -
src/main/java/seedu/cafectrl/command/ExitCommand.java | 1 +
src/main/java/seedu/cafectrl/ui/Ui.java | 4 ++--
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
index e1b6aad114..5112fa3f95 100644
--- a/src/main/java/seedu/cafectrl/CafeCtrl.java
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -1,7 +1,6 @@
package seedu.cafectrl;
import seedu.cafectrl.command.Command;
-import seedu.cafectrl.command.ExitCommand;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.parser.Parser;
import seedu.cafectrl.ui.Ui;
diff --git a/src/main/java/seedu/cafectrl/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
index 4cf2685ef7..1ef0856578 100644
--- a/src/main/java/seedu/cafectrl/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -4,6 +4,7 @@
import seedu.cafectrl.ui.Ui;
public class ExitCommand extends Command {
+
public static final String COMMAND_WORD = "bye";
/**
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index f7ccd895f4..0348a4e989 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -7,7 +7,7 @@
public class Ui {
public static final int OFFSET_LIST_INDEX = 1;
- public static final String lineString = "-----------------------------------------------------";
+ public static final String LINE_STRING = "-----------------------------------------------------";
private final Scanner scanner;
/**
@@ -18,7 +18,7 @@ public Ui() {
}
public void printLine() {
- showToUser(lineString);
+ showToUser(LINE_STRING);
}
public String receiveUserInput() {
From 3b01a433e7853ceea15ec017094e14628381c8f6 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 22:21:37 +0800
Subject: [PATCH 087/870] EditPriceCommand.java: update edit price to
edit_price
---
src/main/java/seedu/duke/command/EditPriceCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/EditPriceCommand.java b/src/main/java/seedu/duke/command/EditPriceCommand.java
index 461d2029b5..d86066784c 100644
--- a/src/main/java/seedu/duke/command/EditPriceCommand.java
+++ b/src/main/java/seedu/duke/command/EditPriceCommand.java
@@ -7,7 +7,7 @@
* Edit the price of a dish of a certain index
*/
public class EditPriceCommand extends Command {
- public static final String COMMAND_WORD = "edit price";
+ public static final String COMMAND_WORD = "edit_price";
private final int menuID;
private final float newPrice;
From 20abc84278a6421e5be06493cdb0619b4103f6f4 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 22:23:43 +0800
Subject: [PATCH 088/870] Implement parser support for edit_price feature
fixes #13
---
src/main/java/seedu/duke/parser/Parser.java | 34 +++++++++++++++++----
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 5fe7372958..2bbc36035c 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -24,7 +24,7 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
// Command Argument Patterns
- private static final String ADD_ARGUMENT_STRING = "add name/(\\w+) price/(\\d+(\\.\\d+)?)" +
+ private static final String ADD_ARGUMENT_STRING = " name/(\\w+) price/(\\d+(\\.\\d+)?)" +
" (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
@@ -62,7 +62,7 @@ public Command parseCommand(Menu menu, String userInput) {
return prepareListMenu();
case EditPriceCommand.COMMAND_WORD:
- return prepareEditListCommand(arguments);
+ return prepareEditPriceCommand(arguments);
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
@@ -80,11 +80,33 @@ private Command prepareListMenu() {
}
/**
- * Parse argument in the context of edit list command
- * @param arguments
- * @return
+ * Parse argument in the context of edit price command
+ * @param arguments string that matches group arguments
+ * @return new EditDishCommand
*/
- private Command prepareEditListCommand(String arguments) {
+ private Command prepareEditPriceCommand(String arguments) {
+ final Pattern EDIT_DISH_ARGUMENT_PATTERN = Pattern.compile(EDIT_PRICE_ARGUMENT_STRING);
+ Matcher matcher = EDIT_DISH_ARGUMENT_PATTERN.matcher(arguments);
+
+ // Checks whether the overall pattern of edit price arguments is correct
+ if (matcher.matches()) {
+ return new IncorrectCommand("Error: Missing arguments for edit price command.");
+ }
+
+ try {
+ int dishIndex = Integer.parseInt(matcher.group(1));
+ float newPrice = Float.parseFloat(matcher.group(2));
+
+ return new EditPriceCommand(dishIndex, newPrice);
+ } catch (IllegalArgumentException e) {
+ return new IncorrectCommand("Oops, seems like you gave me the wrong type for dish index " +
+ "or price. Make sure dish index is of type int " +
+ "and price is of type float!");
+ } catch (IndexOutOfBoundsException e) {
+ return new IncorrectCommand("hmmm, can you double the your dish index, " +
+ "I can't seem to find the dish you're referring to");
+ }
+
}
private Command prepareAdd(String arguments) {
From b7b6c987b205a69bc9bfda9bf6b6bb62604a065e Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 22:32:12 +0800
Subject: [PATCH 089/870] Dish.java: add toString method
---
src/main/java/seedu/duke/data/dish/Dish.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/seedu/duke/data/dish/Dish.java b/src/main/java/seedu/duke/data/dish/Dish.java
index 6e516146e0..91eacd60c2 100644
--- a/src/main/java/seedu/duke/data/dish/Dish.java
+++ b/src/main/java/seedu/duke/data/dish/Dish.java
@@ -33,4 +33,8 @@ public float getPrice() {
public void setPrice(float newPrice) {
this.price = newPrice;
}
+
+ public String toString() {
+ return this.name + " $" + this.price;
+ }
}
From e4a58f40bd283404e96d922aee5bbf1b9c0c7f1b Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 22:33:50 +0800
Subject: [PATCH 090/870] Ui.java: make showToUser and showEditPriceMessage
static
---
src/main/java/seedu/duke/ui/Ui.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index d8cc568a87..c18167d8fd 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -77,13 +77,13 @@ public void showDeleteMessage(Dish selectedDish) {
* Shows messages(s) to the user
* @param message string(s) of messages to print
*/
- public void showToUser(String... message) {
+ public static void showToUser(String... message) {
for (String m: message) {
System.out.println(m);
}
}
- public void showEditPriceMessage(String menuItem) {
+ public static void showEditPriceMessage(String menuItem) {
System.out.println("Modified the following dish: ");
showToUser(menuItem);
}
From d87ddca7b459be077d396635d101e07b267a5036 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 22:38:13 +0800
Subject: [PATCH 091/870] EditPriceCommand.java: show message after execute
Fixes #14
---
.../java/seedu/duke/command/EditPriceCommand.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/EditPriceCommand.java b/src/main/java/seedu/duke/command/EditPriceCommand.java
index d86066784c..875f0a6f7c 100644
--- a/src/main/java/seedu/duke/command/EditPriceCommand.java
+++ b/src/main/java/seedu/duke/command/EditPriceCommand.java
@@ -1,6 +1,7 @@
package seedu.duke.command;
import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
import seedu.duke.ui.Ui;
/**
@@ -16,7 +17,15 @@ public EditPriceCommand(int menuID, float newPrice) {
this.newPrice = newPrice;
}
+ /**
+ * Set new price of the dish and show edit price message
+ * @param menu menu of the current session
+ * @param ui ui of the current session
+ */
public void execute(Menu menu, Ui ui) {
- menu.getDish(this.menuID).setPrice(this.newPrice);
+ Dish dish = menu.getDish(this.menuID);
+ dish.setPrice(this.newPrice);
+
+ Ui.showEditPriceMessage(dish.toString());
}
}
From 31aec2fa86642f1dc57bcb132c4afd5b60260c6f Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 22:47:15 +0800
Subject: [PATCH 092/870] Ui.java: add javadoc for showEditPriceMessage
---
src/main/java/seedu/duke/ui/Ui.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index c18167d8fd..11209bc82a 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -83,8 +83,12 @@ public static void showToUser(String... message) {
}
}
+ /**
+ * show edit price message to user
+ * @param menuItem menuItem that has been modified
+ */
public static void showEditPriceMessage(String menuItem) {
- System.out.println("Modified the following dish: ");
+ System.out.println("Price modified for the following dish: ");
showToUser(menuItem);
}
}
From 1c1742d4902012be02dfe7409ac94eb0e17f45e9 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 22:53:50 +0800
Subject: [PATCH 093/870] Handle out of bounds input index
---
.../java/seedu/duke/command/DeleteDishCommand.java | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java
index 8431705a2f..ec93505b87 100644
--- a/src/main/java/seedu/duke/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java
@@ -15,14 +15,18 @@ public class DeleteDishCommand extends Command {
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
+ public DeleteDishCommand(int listIndex) {
+ this.index = listIndex;
+ }
+
@Override
public void execute(Menu menu, Ui ui) {
- Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
- if (selectedDish != null) {
- ui.showDeleteMessage(selectedDish);
- } else {
+ if (index < 0 || index > menu.getSize()) {
ui.showToUser("Please select a valid dish index :)");
+ } else {
+ Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
+ ui.showDeleteMessage(selectedDish);
+ menu.removeDish(index);
}
- menu.removeDish(index);
}
}
From 39edc4758bf49b45c071bbe3f2bb0612d87381b3 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 22:55:26 +0800
Subject: [PATCH 094/870] Add JUnit test for Delete Command valid and invalid
input
Fixes #55
---
src/main/java/seedu/duke/parser/Parser.java | 2 +-
.../duke/command/DeleteDishCommandTest.java | 59 +++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 38ebf93198..8e78cbf851 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -146,7 +146,7 @@ private static Command prepareListIngredient(String userInput) {
private static Command prepareDelete(String userInput) {
try {
final int listIndex = parseArgsAsDisplayedIndex(userInput, DeleteDishCommand.COMMAND_WORD);
- return new DeleteDishCommand();
+ return new DeleteDishCommand(listIndex);
} catch (ParseException e) {
return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE);
} catch (NumberFormatException nfe) {
diff --git a/src/test/java/seedu/duke/command/DeleteDishCommandTest.java b/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
index b76f003c48..c0da401d46 100644
--- a/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
+++ b/src/test/java/seedu/duke/command/DeleteDishCommandTest.java
@@ -1,5 +1,64 @@
package seedu.duke.command;
+import org.junit.jupiter.api.Test;
+import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
+import seedu.duke.ui.Ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
class DeleteDishCommandTest {
+ @Test
+ void execute_validInput() throws Exception {
+ ArrayList menuItems = new ArrayList<>();
+ Menu menu = new Menu(menuItems);
+ menu.addDish(new Dish("Chicken Rice", 2.50F));
+ menu.addDish(new Dish("Chicken Curry", 4.30F));
+ menu.addDish(new Dish("Nasi Lemak", 5.60F));
+
+ ArrayList actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ int testIndex = 2;
+ DeleteDishCommand deleteDishCommand = new DeleteDishCommand(testIndex);
+ deleteDishCommand.execute(menu, ui);
+
+ int actualOutputIndex = 0;
+ String expectedOutput = "Okay! Chicken Curry is deleted! :)";
+ assertEquals(expectedOutput, actualOutput.get(actualOutputIndex));
+ }
+
+ @Test
+ void execute_invalidInput() throws Exception {
+ ArrayList menuItems = new ArrayList<>();
+ Menu menu = new Menu(menuItems);
+ menu.addDish(new Dish("Chicken Rice", 2.50F));
+ menu.addDish(new Dish("Chicken Curry", 4.30F));
+ menu.addDish(new Dish("Nasi Lemak", 5.60F));
+
+ ArrayList actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ int testIndex = 5;
+ DeleteDishCommand deleteDishCommand = new DeleteDishCommand(testIndex);
+ deleteDishCommand.execute(menu, ui);
+
+ int actualOutputIndex = 0;
+ String expectedOutput = "Please select a valid dish index :)";
+ assertEquals(expectedOutput, actualOutput.get(actualOutputIndex));
+ }
}
From 31be1a09cca6f201e27ca77b56b7b58c660e54fb Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 22:57:21 +0800
Subject: [PATCH 095/870] Update JUnit to include assertion
---
.../java/seedu/cafectrl/command/ListMenuCommandTest.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index 54222baaaf..de3d160055 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -7,13 +7,16 @@
import java.util.ArrayList;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
class ListMenuCommandTest {
@Test
- public static void execute_expectTwoDishes() {
+ public void execute_expectTwoDishes() {
ArrayList menuItems = new ArrayList<>();
menuItems.add(new Dish("Chicken Rice", 2.50F));
menuItems.add(new Dish("Chicken Curry", 4.30F));
Menu menu = new Menu(menuItems);
+ assertEquals(2, menu.getSize());
Command listMenuCommand = new ListMenuCommand();
listMenuCommand.execute(menu, new Ui());
From 0bfb9deb1c64b443917db9cf43fd1941db44c731 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 22:58:08 +0800
Subject: [PATCH 096/870] Update Parser to support ListMenuCommand
---
src/main/java/seedu/cafectrl/parser/Parser.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index e9b92de9db..2a8c5145fb 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -70,8 +70,7 @@ public static Command parseCommand(Menu menu, String userInput) {
// All prepareCommand Classes
private static Command prepareListMenu() {
- // To be implemented by xx
- return null;
+ return new ListMenuCommand();
}
private static Command prepareAdd(String arguments) {
From 2374d2890158c0441811d369ecfb121d1c23bc25 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Tue, 17 Oct 2023 23:03:20 +0800
Subject: [PATCH 097/870] Update JUnit test case name to comply with standards
---
src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index de3d160055..94a2ba2f49 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -11,7 +11,7 @@
class ListMenuCommandTest {
@Test
- public void execute_expectTwoDishes() {
+ public void execute_addTwoDishes_expectTwoDishes() {
ArrayList menuItems = new ArrayList<>();
menuItems.add(new Dish("Chicken Rice", 2.50F));
menuItems.add(new Dish("Chicken Curry", 4.30F));
From a1926699bd7da67ea47b9daa1148860d14cbb2ab Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Tue, 17 Oct 2023 23:09:28 +0800
Subject: [PATCH 098/870] Parser.java: rename ADD_ARGUMENT_STRING and
EDIT_DISH_ARGUMENT to camelCase
---
src/main/java/seedu/duke/parser/Parser.java | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 2bbc36035c..e5a136f087 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -24,7 +24,7 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
// Command Argument Patterns
- private static final String ADD_ARGUMENT_STRING = " name/(\\w+) price/(\\d+(\\.\\d+)?)" +
+ private static final String ADD_ARGUMENT_STRING = "name/(\\w+) price/(\\d+(\\.\\d+)?)" +
" (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
@@ -85,8 +85,8 @@ private Command prepareListMenu() {
* @return new EditDishCommand
*/
private Command prepareEditPriceCommand(String arguments) {
- final Pattern EDIT_DISH_ARGUMENT_PATTERN = Pattern.compile(EDIT_PRICE_ARGUMENT_STRING);
- Matcher matcher = EDIT_DISH_ARGUMENT_PATTERN.matcher(arguments);
+ Pattern editDishArgumentsPattern = Pattern.compile(EDIT_PRICE_ARGUMENT_STRING);
+ Matcher matcher = editDishArgumentsPattern.matcher(arguments);
// Checks whether the overall pattern of edit price arguments is correct
if (matcher.matches()) {
@@ -106,12 +106,11 @@ private Command prepareEditPriceCommand(String arguments) {
return new IncorrectCommand("hmmm, can you double the your dish index, " +
"I can't seem to find the dish you're referring to");
}
-
}
private Command prepareAdd(String arguments) {
- final Pattern ADD_ARGUMENT_PATTERN = Pattern.compile(ADD_ARGUMENT_STRING);
- Matcher matcher = ADD_ARGUMENT_PATTERN.matcher(arguments);
+ final Pattern addArgumentPatter = Pattern.compile(ADD_ARGUMENT_STRING);
+ Matcher matcher = addArgumentPatter.matcher(arguments);
// Checks whether the overall pattern of add arguments is correct
if (matcher.matches()) {
From 1bd674a5beecdb86bfec754b7b106c70180ce148 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Tue, 17 Oct 2023 23:34:06 +0800
Subject: [PATCH 099/870] Update import path
---
.../java/seedu/cafectrl/command/DeleteDishCommandTest.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
index 60cd66ee40..01dc841e39 100644
--- a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
@@ -1,9 +1,10 @@
package seedu.cafectrl.command;
import org.junit.jupiter.api.Test;
-import seedu.duke.data.Menu;
-import seedu.duke.data.dish.Dish;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Ui;
+
import java.util.ArrayList;
import java.util.Arrays;
From aa96baada7a5530ba329e33200dc264f6b09434e Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Wed, 18 Oct 2023 00:40:36 +0800
Subject: [PATCH 100/870] Update code to remove use of Magic String
---
src/main/java/seedu/cafectrl/command/ListMenuCommand.java | 4 +---
src/main/java/seedu/cafectrl/parser/Parser.java | 4 ++--
src/main/java/seedu/cafectrl/ui/UserOutput.java | 3 ++-
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index 1ec2f5064c..af2584c8c6 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -6,8 +6,6 @@
import java.text.DecimalFormat;
-import java.text.DecimalFormat;
-
/**
* Lists all dishes in the menu to the user.
*/
@@ -15,13 +13,13 @@ public class ListMenuCommand extends Command {
public static final String COMMAND_WORD = "list_menu";
private static final DecimalFormat dollarValue = new DecimalFormat("0.00");
+
/**
* Iterates through the menu arraylist, outputting the dish name and dish price.
*
* @param menu ArrayList of Dishes
* @param ui Handles the interactions with user
*/
-
@Override
public void execute(Menu menu, Ui ui) {
ui.showToUser(UserOutput.LIST_MESSAGE.message);
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 2a8c5145fb..d7da54916e 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -8,6 +8,7 @@
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.command.ListMenuCommand;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.UserOutput;
import java.util.ArrayList;
import java.util.regex.Matcher;
@@ -63,8 +64,7 @@ public static Command parseCommand(Menu menu, String userInput) {
return new ExitCommand();
default:
- return new IncorrectCommand("Your command has left me scratching my virtual head. " +
- "Let's try that again, shall we?");
+ return new IncorrectCommand(UserOutput.UNKNOWN_COMMAND_MESSAGE.message);
}
}
diff --git a/src/main/java/seedu/cafectrl/ui/UserOutput.java b/src/main/java/seedu/cafectrl/ui/UserOutput.java
index 8f31c08064..682d1231f6 100644
--- a/src/main/java/seedu/cafectrl/ui/UserOutput.java
+++ b/src/main/java/seedu/cafectrl/ui/UserOutput.java
@@ -7,7 +7,8 @@ public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
LIST_MESSAGE("Ah, behold, the grand menu of delights!"),
- ADD_DISH_MESSAGE("You have added the following dish...");
+ ADD_DISH_MESSAGE("You have added the following dish..."),
+ UNKNOWN_COMMAND_MESSAGE("Your command has left me scratching my virtual head. Let's try that again, shall we?");
public final String message;
UserOutput(String message) {
From e991c9db72a04d04051bbd6fef381a324a2f7b05 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 00:43:40 +0800
Subject: [PATCH 101/870] Parser.java: remove wildcard import
---
src/main/java/seedu/cafectrl/parser/Parser.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index f6c385788b..71b49b0f4f 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -1,6 +1,14 @@
package seedu.cafectrl.parser;
-import seedu.cafectrl.command.*;
+import seedu.cafectrl.command.AddDishCommand;
+import seedu.cafectrl.command.Command;
+import seedu.cafectrl.command.IncorrectCommand;
+import seedu.cafectrl.command.DeleteDishCommand;
+import seedu.cafectrl.command.EditPriceCommand;
+import seedu.cafectrl.command.ExitCommand;
+import seedu.cafectrl.command.ListIngredientCommand;
+import seedu.cafectrl.command.ListMenuCommand;
+
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.command.EditPriceCommand;
From d3f5e998de9b97220a2fb1c5de9e42ed1565e310 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 00:44:46 +0800
Subject: [PATCH 102/870] Parser.java: remove duplicated import
---
src/main/java/seedu/cafectrl/parser/Parser.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 71b49b0f4f..e10ec23985 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -11,8 +11,6 @@
import seedu.cafectrl.data.Menu;
-import seedu.cafectrl.command.EditPriceCommand;
-
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
From 02f561afd0972856a346bb73cfd099c3414c1fd7 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 01:17:14 +0800
Subject: [PATCH 103/870] Add try-catch error handler
---
.../java/seedu/cafectrl/command/DeleteDishCommand.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
index baad47185e..d615c4e0f1 100644
--- a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
@@ -10,6 +10,7 @@
public class DeleteDishCommand extends Command {
public static final String COMMAND_WORD = "delete";
+ public static final String INVALID_INDEX_MESSAGE = "Please select a valid dish index :)";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the menu item identified by the index number used in the last menu listing.\n"
+ "Parameters: INDEX\n"
@@ -21,12 +22,12 @@ public DeleteDishCommand(int listIndex) {
@Override
public void execute(Menu menu, Ui ui) {
- if (index < 0 || index > menu.getSize()) {
- ui.showToUser("Please select a valid dish index :)");
- } else {
+ try {
Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
ui.showDeleteMessage(selectedDish);
menu.removeDish(index);
+ } catch (IndexOutOfBoundsException e) {
+ ui.showToUser(INVALID_INDEX_MESSAGE);
}
}
}
From 2fb7143c3608035bd2598e54e161afa8f31bac17 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Wed, 18 Oct 2023 01:38:22 +0800
Subject: [PATCH 104/870] Add Junit test for list ingredient command.
Fixes #56
---
.../duke/command/ListIngredientCommand.java | 8 +--
src/main/java/seedu/duke/ui/Ui.java | 6 ++-
.../command/ListIngredientCommandTest.java | 51 +++++++++++++++++++
3 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/duke/command/ListIngredientCommand.java b/src/main/java/seedu/duke/command/ListIngredientCommand.java
index 90ccca997f..97e1c430b3 100644
--- a/src/main/java/seedu/duke/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/duke/command/ListIngredientCommand.java
@@ -20,11 +20,11 @@ public ListIngredientCommand(int listIndex) {
@Override
public void execute(Menu menu, Ui ui) {
- Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
- if (selectedDish != null) {
+ try {
+ Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
ui.printIngredients(selectedDish);
- } else {
- ui.showToUser("Please select a valid dish index :)");
+ } catch (IndexOutOfBoundsException e) {
+ throw new IllegalArgumentException("Invalid dish index");
}
}
}
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 7b497f6a25..37e209036f 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -35,11 +35,13 @@ public void showGoodbye() {
* @param selectedDish Dish for ingredients to be listed out.
*/
public void printIngredients(Dish selectedDish) {
- showToUser(selectedDish.getName() + " Ingredients: \n");
+ StringBuilder ingredientsString = new StringBuilder(selectedDish.getName() + " Ingredients: \n");
for (Ingredient ingredient : selectedDish.getIngredients()) {
- showToUser(ingredient.getName() + " - " + ingredient.getQuantity());
+ ingredientsString.append(ingredient.toString()).append("\n");
}
+
+ showToUser(ingredientsString.toString().trim());
}
public void printAddDishMessage(Dish dish) {
diff --git a/src/test/java/seedu/duke/command/ListIngredientCommandTest.java b/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
index 7247a13efb..d0ce97cc20 100644
--- a/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/duke/command/ListIngredientCommandTest.java
@@ -1,5 +1,56 @@
package seedu.duke.command;
+import org.junit.jupiter.api.Test;
+import seedu.duke.data.Menu;
+import seedu.duke.data.dish.Dish;
+import seedu.duke.data.dish.Ingredient;
+import seedu.duke.ui.Ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
class ListIngredientCommandTest {
+ @Test
+ public void execute_validIndex_printsIngredients() {
+ ArrayList menuItems = new ArrayList<>();
+ menuItems.add(new Dish("Chicken Rice", new ArrayList<>(Arrays.asList(new Ingredient("Rice", "1 cup"), new Ingredient("Chicken", "100g"))), 8.0F));
+ menuItems.add(new Dish("Chicken Sandwich", new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "100g"), new Ingredient("Chicken", "50g"))), 5.0F));
+ Menu menu = new Menu(menuItems);
+
+ List actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ int indexToSelect = 1;
+ ListIngredientCommand listIngredientCommand = new ListIngredientCommand(indexToSelect);
+ listIngredientCommand.execute(menu, ui);
+
+ String expectedOutput = "Chicken Rice Ingredients: \n" +
+ "Rice - 1 cup\n" +
+ "Chicken - 100g\n";
+
+ assertEquals(expectedOutput.trim().replaceAll("\\s+", " "), actualOutput.get(0).trim().replaceAll("\\s+", " "));
+ }
+
+ public void execute_invalidIndex_returnsErrorMessage() {
+ ArrayList menuItems = new ArrayList<>();
+ menuItems.add(new Dish("Chicken Rice", new ArrayList<>(Arrays.asList(new Ingredient("Rice", "1 cup"), new Ingredient("Chicken", "100g"))), 8.0F));
+ menuItems.add(new Dish("Chicken Sandwich", new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "100g"), new Ingredient("Chicken", "50g"))), 5.0F));
+ Menu menu = new Menu(menuItems);
+ Ui ui = new Ui();
+ int invalidIndex = 3;
+ assertThrows(IllegalArgumentException.class, () -> {
+ ListIngredientCommand listIngredientCommand = new ListIngredientCommand(invalidIndex);
+ listIngredientCommand.execute(menu, ui);
+ });
+ }
}
From 4075a3361550a84ae8b24e23fec324f9db30502c Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 01:44:12 +0800
Subject: [PATCH 105/870] Menu.java: add isValidDishIndex method
---
src/main/java/seedu/duke/data/Menu.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/main/java/seedu/duke/data/Menu.java b/src/main/java/seedu/duke/data/Menu.java
index c1abd0b1ef..fc256d59fc 100644
--- a/src/main/java/seedu/duke/data/Menu.java
+++ b/src/main/java/seedu/duke/data/Menu.java
@@ -1,6 +1,7 @@
package seedu.duke.data;
import seedu.duke.data.dish.Dish;
+import seedu.duke.ui.Ui;
import java.util.ArrayList;
@@ -26,4 +27,9 @@ public void removeDish(int menuID) {
public void addDish(Dish dish) {
menuItems.add(dish);
}
+
+ public boolean isValidDishIndex(int dishIndex) {
+ int offSetDishIndex = dishIndex - Ui.OFFSET_LIST_INDEX;
+ return offSetDishIndex >= 0 && offSetDishIndex < this.getSize();
+ }
}
From 7a6a61058cc79064a530c3f47ddd22ce55efd919 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Wed, 18 Oct 2023 01:45:38 +0800
Subject: [PATCH 106/870] Rename imported packages in
ListIngredientCommandTest.java into the new refactored format.
Fixes #56
---
src/main/java/seedu/cafectrl/ui/Ui.java | 6 +++---
.../seedu/cafectrl/command/ListIngredientCommandTest.java | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index a64530b904..f651e07c50 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -41,13 +41,13 @@ public void showGoodbye() {
* @param selectedDish Dish for ingredients to be listed out.
*/
public void printIngredients(Dish selectedDish) {
- StringBuilder ingredientsString = new StringBuilder(selectedDish.getName() + " Ingredients: \n");
+ String ingredientsString = selectedDish.getName() + " Ingredients: \n";
for (Ingredient ingredient : selectedDish.getIngredients()) {
- ingredientsString.append(ingredient.toString()).append("\n");
+ ingredientsString += ingredient.toString() + "\n";
}
- showToUser(ingredientsString.toString().trim());
+ showToUser(ingredientsString.trim());
}
public void printAddDishMessage(Dish dish) {
diff --git a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
index 6397cbac23..c2dc9711da 100644
--- a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
@@ -1,10 +1,10 @@
package seedu.cafectrl.command;
import org.junit.jupiter.api.Test;
-import seedu.duke.data.Menu;
-import seedu.duke.data.dish.Dish;
-import seedu.duke.data.dish.Ingredient;
-import seedu.duke.ui.Ui;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.data.dish.Ingredient;
+import seedu.cafectrl.ui.Ui;
import java.util.ArrayList;
import java.util.Arrays;
From 721151f928162dceba3584c0bd568cef7596a74d Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 01:45:41 +0800
Subject: [PATCH 107/870] Parser.java: remove catch block for
IndexOutOfBoundsException
---
src/main/java/seedu/duke/parser/Parser.java | 20 ++++++++++----------
src/main/java/seedu/duke/ui/Messages.java | 17 +++++++++++++++++
src/main/java/seedu/duke/ui/Ui.java | 2 +-
3 files changed, 28 insertions(+), 11 deletions(-)
create mode 100644 src/main/java/seedu/duke/ui/Messages.java
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index e5a136f087..62d7608f27 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -10,6 +10,7 @@
import seedu.duke.command.ListIngredientCommand;
import seedu.duke.command.ListMenuCommand;
import seedu.duke.command.EditPriceCommand;
+import seedu.duke.ui.Messages;
import java.util.ArrayList;
import java.util.regex.Matcher;
@@ -62,7 +63,7 @@ public Command parseCommand(Menu menu, String userInput) {
return prepareListMenu();
case EditPriceCommand.COMMAND_WORD:
- return prepareEditPriceCommand(arguments);
+ return prepareEditPriceCommand(menu, arguments);
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
@@ -84,27 +85,26 @@ private Command prepareListMenu() {
* @param arguments string that matches group arguments
* @return new EditDishCommand
*/
- private Command prepareEditPriceCommand(String arguments) {
+ private Command prepareEditPriceCommand(Menu menu, String arguments) {
Pattern editDishArgumentsPattern = Pattern.compile(EDIT_PRICE_ARGUMENT_STRING);
Matcher matcher = editDishArgumentsPattern.matcher(arguments);
// Checks whether the overall pattern of edit price arguments is correct
- if (matcher.matches()) {
- return new IncorrectCommand("Error: Missing arguments for edit price command.");
+ if (!matcher.matches()) {
+ return new IncorrectCommand(Messages.MISSING_ARGUMENT_FOR_EDIT_PRICE);
}
try {
int dishIndex = Integer.parseInt(matcher.group(1));
float newPrice = Float.parseFloat(matcher.group(2));
+ // Check whether the dish index is valid
+ if (!menu.isValidDishIndex(dishIndex)) {
+ return new IncorrectCommand(Messages.INVALID_DISH_INDEX);
+ }
return new EditPriceCommand(dishIndex, newPrice);
} catch (IllegalArgumentException e) {
- return new IncorrectCommand("Oops, seems like you gave me the wrong type for dish index " +
- "or price. Make sure dish index is of type int " +
- "and price is of type float!");
- } catch (IndexOutOfBoundsException e) {
- return new IncorrectCommand("hmmm, can you double the your dish index, " +
- "I can't seem to find the dish you're referring to");
+ return new IncorrectCommand(Messages.WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE);
}
}
diff --git a/src/main/java/seedu/duke/ui/Messages.java b/src/main/java/seedu/duke/ui/Messages.java
new file mode 100644
index 0000000000..1d7c88c1f6
--- /dev/null
+++ b/src/main/java/seedu/duke/ui/Messages.java
@@ -0,0 +1,17 @@
+package seedu.duke.ui;
+
+public class Messages {
+
+ // Error messages
+ public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments " +
+ "for edit price command.";
+ public static final String INVALID_DISH_INDEX = "Hmmm, can you double the your dish index, " +
+ "I can't seem to find the dish you're referring to";
+ public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me " +
+ "the wrong type for dish index " +
+ "or price. Make sure dish index is of type int " +
+ "and price is of type float!";
+
+ // Ui messages
+ public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
+}
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java
index 11209bc82a..77cd1cb2ec 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/Ui.java
@@ -88,7 +88,7 @@ public static void showToUser(String... message) {
* @param menuItem menuItem that has been modified
*/
public static void showEditPriceMessage(String menuItem) {
- System.out.println("Price modified for the following dish: ");
+ System.out.println(Messages.PRICE_MODIFIED_MESSAGE);
showToUser(menuItem);
}
}
From 421167b78f8a3be9664ab6d40146164793398dc6 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Wed, 18 Oct 2023 01:57:50 +0800
Subject: [PATCH 108/870] Improve coding standard.
Fixes #56
---
.../command/ListIngredientCommandTest.java | 22 +++++++++++++------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
index c2dc9711da..86c7869935 100644
--- a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -17,11 +16,15 @@ class ListIngredientCommandTest {
@Test
public void execute_validIndex_printsIngredients() {
ArrayList menuItems = new ArrayList<>();
- menuItems.add(new Dish("Chicken Rice", new ArrayList<>(Arrays.asList(new Ingredient("Rice", "1 cup"), new Ingredient("Chicken", "100g"))), 8.0F));
- menuItems.add(new Dish("Chicken Sandwich", new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "100g"), new Ingredient("Chicken", "50g"))), 5.0F));
+ menuItems.add(new Dish("Chicken Rice",
+ new ArrayList<>(Arrays.asList(new Ingredient("Rice", "1 cup"),
+ new Ingredient("Chicken", "100g"))), 8.0F));
+ menuItems.add(new Dish("Chicken Sandwich",
+ new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "100g"),
+ new Ingredient("Chicken", "50g"))), 5.0F));
Menu menu = new Menu(menuItems);
- List actualOutput = new ArrayList<>();
+ ArrayList actualOutput = new ArrayList<>();
Ui ui = new Ui() {
@Override
public void showToUser(String... message) {
@@ -37,13 +40,18 @@ public void showToUser(String... message) {
"Rice - 1 cup\n" +
"Chicken - 100g\n";
- assertEquals(expectedOutput.trim().replaceAll("\\s+", " "), actualOutput.get(0).trim().replaceAll("\\s+", " "));
+ assertEquals(expectedOutput.trim().replaceAll("\\s+", " "),
+ actualOutput.get(0).trim().replaceAll("\\s+", " "));
}
public void execute_invalidIndex_returnsErrorMessage() {
ArrayList menuItems = new ArrayList<>();
- menuItems.add(new Dish("Chicken Rice", new ArrayList<>(Arrays.asList(new Ingredient("Rice", "1 cup"), new Ingredient("Chicken", "100g"))), 8.0F));
- menuItems.add(new Dish("Chicken Sandwich", new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "100g"), new Ingredient("Chicken", "50g"))), 5.0F));
+ menuItems.add(new Dish("Chicken Rice",
+ new ArrayList<>(Arrays.asList(new Ingredient("Rice", "1 cup"),
+ new Ingredient("Chicken", "100g"))), 8.0F));
+ menuItems.add(new Dish("Chicken Sandwich",
+ new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "100g"),
+ new Ingredient("Chicken", "50g"))), 5.0F));
Menu menu = new Menu(menuItems);
Ui ui = new Ui();
int invalidIndex = 3;
From d8fd274670ac311f83fcb2090492a94c62379017 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 02:59:48 +0800
Subject: [PATCH 109/870] Ui.java: remove static from showToUser
---
src/main/java/seedu/cafectrl/ui/Ui.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 71b32e8803..2983643416 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -85,7 +85,7 @@ public void showDeleteMessage(Dish selectedDish) {
* Shows messages(s) to the user
* @param message string(s) of messages to print
*/
- public static void showToUser(String... message) {
+ public void showToUser(String... message) {
for (String m: message) {
System.out.println(m);
}
@@ -95,8 +95,8 @@ public static void showToUser(String... message) {
* show edit price message to user
* @param menuItem menuItem that has been modified
*/
- public static void showEditPriceMessage(String menuItem) {
+ public void showEditPriceMessage(String menuItem) {
System.out.println(Messages.PRICE_MODIFIED_MESSAGE);
- showToUser(menuItem);
+ this.showToUser(menuItem);
}
}
From edf108043148d24277cf8430c989201972ec2c45 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 03:00:27 +0800
Subject: [PATCH 110/870] Improve code quality with gradlew
---
src/main/java/seedu/cafectrl/command/EditPriceCommand.java | 2 +-
src/main/java/seedu/cafectrl/parser/Parser.java | 2 +-
src/main/java/seedu/cafectrl/ui/Messages.java | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
index 30024ba892..e5ad74ae4e 100644
--- a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
+++ b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
@@ -26,6 +26,6 @@ public void execute(Menu menu, Ui ui) {
Dish dish = menu.getDish(this.menuID);
dish.setPrice(this.newPrice);
- Ui.showEditPriceMessage(dish.toString());
+ ui.showEditPriceMessage(dish.toString());
}
}
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 99bdcb35be..d93d44f047 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -9,7 +9,7 @@
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.command.ListMenuCommand;
-import seedu.duke.ui.Messages;
+import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.ui.UserOutput;
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index ed23e44e0e..99790ee364 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -9,8 +9,8 @@ public class Messages {
"I can't seem to find the dish you're referring to";
public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me " +
"the wrong type for dish index " +
- "or price. Make sure dish index is of type int " +
- "and price is of type float!";
+ "or price. Make sure dish index is " +
+ "of type int and price is of type float!";
// Ui messages
public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
From d128fc7c9682256fea60137e194f239e52521613 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Wed, 18 Oct 2023 11:49:52 +0800
Subject: [PATCH 111/870] Messages.java: update position of plus operator for
strings
---
src/main/java/seedu/cafectrl/ui/Messages.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 99790ee364..b6717e1cec 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -5,12 +5,12 @@ public class Messages {
// Error messages
public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments " +
"for edit price command.";
- public static final String INVALID_DISH_INDEX = "Hmmm, can you double the your dish index, " +
- "I can't seem to find the dish you're referring to";
- public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me " +
- "the wrong type for dish index " +
- "or price. Make sure dish index is " +
- "of type int and price is of type float!";
+ public static final String INVALID_DISH_INDEX = "Hmmm, can you double the your dish index, "
+ + "I can't seem to find the dish you're referring to";
+ public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me "
+ + "the wrong type for dish index "
+ + "or price. Make sure dish index is "
+ + "of type int and price is of type float!";
// Ui messages
public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
From bd4181f11168d9c3e1b34bf16a0f7efa37f68418 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Wed, 18 Oct 2023 11:56:22 +0800
Subject: [PATCH 112/870] Parser.java: update position of plus operator
---
src/main/java/seedu/cafectrl/parser/Parser.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index d93d44f047..c2de427150 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -26,8 +26,8 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
// Command Argument Patterns
- private static final String ADD_ARGUMENT_STRING = "name/(\\w+) price/(\\d+(\\.\\d+)?)" +
- " (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
+ private static final String ADD_ARGUMENT_STRING = "name/(\\w+) price/(\\d+(\\.\\d+)?)"
+ + " (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
From defbb3e75f20842edf6faa71e54688a3367ed1d6 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Wed, 18 Oct 2023 11:58:01 +0800
Subject: [PATCH 113/870] Messages.java: Update position of plus operator for
MISSING_ARGUMENT_FOR_EDIT_PRICE
---
src/main/java/seedu/cafectrl/ui/Messages.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index b6717e1cec..03b7ff3feb 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -3,11 +3,11 @@
public class Messages {
// Error messages
- public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments " +
- "for edit price command.";
+ public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments "
+ + "for edit price command.";
public static final String INVALID_DISH_INDEX = "Hmmm, can you double the your dish index, "
+ "I can't seem to find the dish you're referring to";
- public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me "
+ public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me "
+ "the wrong type for dish index "
+ "or price. Make sure dish index is "
+ "of type int and price is of type float!";
From cd65ca12b9a4aa2d948b592690f25f2f23c10502 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 13:38:00 +0800
Subject: [PATCH 114/870] Create parsing logic for add command
---
.../java/seedu/cafectrl/parser/Parser.java | 59 +++++++++++--------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index e9b92de9db..6e823ef85f 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -8,6 +8,8 @@
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.command.ListMenuCommand;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.data.dish.Ingredient;
import java.util.ArrayList;
import java.util.regex.Matcher;
@@ -19,11 +21,11 @@
* into a format that can be interpreted by other core classes
*/
public class Parser {
- public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)(?.*)");
+ public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+) (?.*)");
// Command Argument Patterns
- private static final String ADD_ARGUMENT_STRING = "add name/(\\w+) price/(\\d+(\\.\\d+)?)" +
- " (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
+// private static final String ADD_ARGUMENT_STRING = "add name/(\\w+) price/(\\d+(\\.\\d+)?) (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
+ private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) price/([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))? (ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
@@ -79,45 +81,50 @@ private static Command prepareAdd(String arguments) {
Matcher matcher = addArgumentPattern.matcher(arguments);
// Checks whether the overall pattern of add arguments is correct
- if (matcher.matches()) {
- return new IncorrectCommand("Error: Missing arguments for the add command.");
+ if (!matcher.matches()) {
+ return new IncorrectCommand("Error: Incorrect format for the add command.");
}
try {
// To retrieve specific arguments from arguments
String dishName = matcher.group(1);
float price = Float.parseFloat(matcher.group(2));
+ String ingredientsListString = matcher.group(4);
+
+ // Capture the list of ingredients
+ ArrayList ingredients = new ArrayList<>();
+ String[] ingredientListInputText = {ingredientsListString};
+
+ //check if there is more than 1 ingredient
+ if (ingredientsListString.contains(",")) {
+ //split the ingredients into separate individual ingredients
+ ingredientListInputText = ingredientsListString.split(", ");
+ }
- // Capture the list of ingredients and quantities
- ArrayList ingredients = new ArrayList<>();
- ArrayList quantities = new ArrayList<>();
+ for (String inputIngredientText: ingredientListInputText) {
+ final Pattern ingredientPattern = Pattern.compile("ingredient/(?[A-Za-z0-9\\s]+) qty/(?[A-Za-z0-9\\s]+)");
+ Matcher ingredientMatcher = ingredientPattern.matcher(inputIngredientText);
- // Find all matches for ingredients and quantities
- Pattern ingredientPattern = Pattern.compile("ingredient/([A-Za-z]+) qty/([A-Za-z]+)");
- Matcher ingredientMatcher = ingredientPattern.matcher(arguments);
+ if (!ingredientMatcher.matches()) {
+ return new IncorrectCommand("Error: Incorrect format for the ingredients");
+ }
+
+ String ingredientName = ingredientMatcher.group("name");
+ String ingredientQty = ingredientMatcher.group("qty");
+
+ Ingredient ingredient = new Ingredient(ingredientName, ingredientQty);
- while (ingredientMatcher.find()) {
- String ingredient = ingredientMatcher.group(1);
- String quantity = ingredientMatcher.group(2);
ingredients.add(ingredient);
- quantities.add(quantity);
}
- // Todo: Implement error handling for checking the size of ingredients quantities
- // I am not sure if this is necessary as we have already checked
- // the overall command pattern in line 62
-
- // Todo: Add the attributes in AddDishCommand
- // Todo: Overload the constructor of Dish such that
- // it can take in ingredients list and quantities list
- // and create an arrayList of ingredient objects
- // return new AddDishCommand(dishName, price, ingredients, quantities);
+ Dish dish = new Dish(dishName, ingredients, price);
+ return new AddDishCommand(dish);
} catch (Exception e) {
// Todo: Add error handling for invalid price type etc.
+ return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT");
}
- return new IncorrectCommand("The specific details are " +
- "to be implemented by Dexter");
+
}
/**
From e7ca9e70c6a75d581ac6d8fa41cf173be97da596 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 18:09:14 +0800
Subject: [PATCH 115/870] Parser.java: replace matcher.matches() with
matcher.find() in line 96
---
src/main/java/seedu/cafectrl/parser/Parser.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index c2de427150..edc4d0ed7d 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -93,7 +93,7 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments) {
Matcher matcher = editDishArgumentsPattern.matcher(arguments);
// Checks whether the overall pattern of edit price arguments is correct
- if (!matcher.matches()) {
+ if (!matcher.find()) {
return new IncorrectCommand(Messages.MISSING_ARGUMENT_FOR_EDIT_PRICE);
}
From 54e6c789b799b86d458d6a74ee4d57e8362a1fa2 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 18:33:25 +0800
Subject: [PATCH 116/870] EditPriceCommand.java: minus offset for menuID
---
src/main/java/seedu/cafectrl/command/EditPriceCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
index e5ad74ae4e..0c4b968ba2 100644
--- a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
+++ b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
@@ -23,7 +23,7 @@ public EditPriceCommand(int menuID, float newPrice) {
* @param ui ui of the current session
*/
public void execute(Menu menu, Ui ui) {
- Dish dish = menu.getDish(this.menuID);
+ Dish dish = menu.getDish(this.menuID - Ui.OFFSET_LIST_INDEX);
dish.setPrice(this.newPrice);
ui.showEditPriceMessage(dish.toString());
From 662573be694dfbb3b724a75cb1523a54ed7d65be Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 19:33:47 +0800
Subject: [PATCH 117/870] Refactor prepareAdd method
---
.../java/seedu/cafectrl/parser/Parser.java | 58 +++++++++++--------
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 6e823ef85f..c34d7ac7e4 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -24,11 +24,15 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+) (?.*)");
// Command Argument Patterns
-// private static final String ADD_ARGUMENT_STRING = "add name/(\\w+) price/(\\d+(\\.\\d+)?) (ingredient/\\w+ qty/\\d+(\\.\\d+)?(?:, )?)+";
private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) price/([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))? (ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)";
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
+ public static final String INGREDIENT_ARGUMENT_STRING = "ingredient/(?[A-Za-z0-9\\s]+) qty/(?[A-Za-z0-9\\s]+)";
+ public static final String INGREDIENT_DIVIDER_REGEX = ", ";
+ public static final String INGREDIENT_DIVIDER_STRING = ",";
+ public static final String INGREDIENT_NAME_REGEX_GROUP_LABEL = "name";
+ public static final String INGREDIENT_QTY_REGEX_GROUP_LABEL = "qty";
/**
* Parse userInput and group it under commandWord and arguments
@@ -93,40 +97,46 @@ private static Command prepareAdd(String arguments) {
// Capture the list of ingredients
ArrayList ingredients = new ArrayList<>();
- String[] ingredientListInputText = {ingredientsListString};
- //check if there is more than 1 ingredient
- if (ingredientsListString.contains(",")) {
- //split the ingredients into separate individual ingredients
- ingredientListInputText = ingredientsListString.split(", ");
- }
+ IncorrectCommand incorrectCommand = ingredientParsing(ingredientsListString, ingredients);
+ if (incorrectCommand != null) return incorrectCommand;
- for (String inputIngredientText: ingredientListInputText) {
- final Pattern ingredientPattern = Pattern.compile("ingredient/(?[A-Za-z0-9\\s]+) qty/(?[A-Za-z0-9\\s]+)");
- Matcher ingredientMatcher = ingredientPattern.matcher(inputIngredientText);
+ Dish dish = new Dish(dishName, ingredients, price);
- if (!ingredientMatcher.matches()) {
- return new IncorrectCommand("Error: Incorrect format for the ingredients");
- }
+ return new AddDishCommand(dish);
+ } catch (Exception e) {
+ return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT");
+ }
+ }
- String ingredientName = ingredientMatcher.group("name");
- String ingredientQty = ingredientMatcher.group("qty");
+ private static IncorrectCommand ingredientParsing(String ingredientsListString, ArrayList ingredients) {
+ String[] ingredientListInputText = {ingredientsListString};
+
+ //check if there is more than 1 ingredient
+ if (ingredientsListString.contains(INGREDIENT_DIVIDER_STRING)) {
+ //split the ingredients into separate individual ingredients
+ ingredientListInputText = ingredientsListString.split(INGREDIENT_DIVIDER_REGEX);
+ }
- Ingredient ingredient = new Ingredient(ingredientName, ingredientQty);
+ for (String inputIngredientText: ingredientListInputText) {
+ final Pattern ingredientPattern = Pattern.compile(INGREDIENT_ARGUMENT_STRING);
+ Matcher ingredientMatcher = ingredientPattern.matcher(inputIngredientText);
- ingredients.add(ingredient);
+ if (!ingredientMatcher.matches()) {
+ return new IncorrectCommand("Error: Incorrect format for the ingredients");
}
- Dish dish = new Dish(dishName, ingredients, price);
- return new AddDishCommand(dish);
- } catch (Exception e) {
- // Todo: Add error handling for invalid price type etc.
- return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT");
- }
+ String ingredientName = ingredientMatcher.group(INGREDIENT_NAME_REGEX_GROUP_LABEL);
+ String ingredientQty = ingredientMatcher.group(INGREDIENT_QTY_REGEX_GROUP_LABEL);
+ Ingredient ingredient = new Ingredient(ingredientName, ingredientQty);
+ ingredients.add(ingredient);
+ }
+ return null;
}
-
+
+
/**
* Parses arguments in the context of the ListIngredient command.
* @param userInput arguments string to parse as index number
From 1efc60f9586f0d30b7825876730b0b655c88eeb7 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 20:14:00 +0800
Subject: [PATCH 118/870] Edit error messages for add dish parsing
---
src/main/java/seedu/cafectrl/command/AddDishCommand.java | 6 ++++++
src/main/java/seedu/cafectrl/parser/Parser.java | 9 ++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/AddDishCommand.java b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
index b48e2f7e7e..bcccc21db1 100644
--- a/src/main/java/seedu/cafectrl/command/AddDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
@@ -9,6 +9,12 @@
*/
public class AddDishCommand extends Command {
public static final String COMMAND_WORD = "add";
+ public static final String MESSAGE_USAGE = COMMAND_WORD
+ + ": Add dish to menu\n"
+ + "Parameters: DISH_NAME, PRICE, INGREDIENT1_NAME, INGREDIENT1_QTY "
+ + "[,INGREDIENT1_NAME, INGREDIENT1_QTY...] \n"
+ + "Example: " + COMMAND_WORD
+ + " name/chicken rice price/3 ingredient/rice qty/1 cup, ingredient/chicken qty/100g";
Dish dish;
public AddDishCommand(Dish dish) {
this.dish = dish;
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index c34d7ac7e4..7aaf9381ec 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -86,7 +86,8 @@ private static Command prepareAdd(String arguments) {
// Checks whether the overall pattern of add arguments is correct
if (!matcher.matches()) {
- return new IncorrectCommand("Error: Incorrect format for the add command.");
+ return new IncorrectCommand("Error: Incorrect format for the add command.\n"
+ + AddDishCommand.MESSAGE_USAGE);
}
try {
@@ -105,7 +106,8 @@ private static Command prepareAdd(String arguments) {
return new AddDishCommand(dish);
} catch (Exception e) {
- return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT");
+ return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT"
+ + AddDishCommand.MESSAGE_USAGE);
}
}
@@ -123,7 +125,8 @@ private static IncorrectCommand ingredientParsing(String ingredientsListString,
Matcher ingredientMatcher = ingredientPattern.matcher(inputIngredientText);
if (!ingredientMatcher.matches()) {
- return new IncorrectCommand("Error: Incorrect format for the ingredients");
+ return new IncorrectCommand("Error: Incorrect format for the ingredients\n"
+ + AddDishCommand.MESSAGE_USAGE);
}
String ingredientName = ingredientMatcher.group(INGREDIENT_NAME_REGEX_GROUP_LABEL);
From a91ce9760719dd42f2a4f04b5945d19194e15e02 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 20:17:45 +0800
Subject: [PATCH 119/870] Remove magic numbers in prepareAdd method
---
src/main/java/seedu/cafectrl/parser/Parser.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 7aaf9381ec..a0dd2e00ec 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -33,6 +33,9 @@ public class Parser {
public static final String INGREDIENT_DIVIDER_STRING = ",";
public static final String INGREDIENT_NAME_REGEX_GROUP_LABEL = "name";
public static final String INGREDIENT_QTY_REGEX_GROUP_LABEL = "qty";
+ public static final int DISH_NAME_MATCHER_GROUP_NUM = 1;
+ public static final int PRICE_MATCHER_GROUP_NUM = 2;
+ public static final int INGREDIENT_LIST_MATCHER_GROUP_NUM = 4;
/**
* Parse userInput and group it under commandWord and arguments
@@ -92,9 +95,9 @@ private static Command prepareAdd(String arguments) {
try {
// To retrieve specific arguments from arguments
- String dishName = matcher.group(1);
- float price = Float.parseFloat(matcher.group(2));
- String ingredientsListString = matcher.group(4);
+ String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_NUM);
+ float price = Float.parseFloat(matcher.group(PRICE_MATCHER_GROUP_NUM));
+ String ingredientsListString = matcher.group(INGREDIENT_LIST_MATCHER_GROUP_NUM);
// Capture the list of ingredients
ArrayList ingredients = new ArrayList<>();
From b288c8a7fe69918fc91bbaeaeacb7b0e4a3d3e22 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 20:23:36 +0800
Subject: [PATCH 120/870] Edit printAddDishMessage method to display price in 2
decimal place
---
src/main/java/seedu/cafectrl/command/AddDishCommand.java | 2 +-
src/main/java/seedu/cafectrl/ui/Ui.java | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/AddDishCommand.java b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
index bcccc21db1..38aa723e3c 100644
--- a/src/main/java/seedu/cafectrl/command/AddDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
@@ -14,7 +14,7 @@ public class AddDishCommand extends Command {
+ "Parameters: DISH_NAME, PRICE, INGREDIENT1_NAME, INGREDIENT1_QTY "
+ "[,INGREDIENT1_NAME, INGREDIENT1_QTY...] \n"
+ "Example: " + COMMAND_WORD
- + " name/chicken rice price/3 ingredient/rice qty/1 cup, ingredient/chicken qty/100g";
+ + " name/chicken rice price/3.00 ingredient/rice qty/1 cup, ingredient/chicken qty/100g";
Dish dish;
public AddDishCommand(Dish dish) {
this.dish = dish;
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 0348a4e989..715289debc 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -3,6 +3,7 @@
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
+import java.text.DecimalFormat;
import java.util.Scanner;
public class Ui {
@@ -50,7 +51,9 @@ public void printIngredients(Dish selectedDish) {
public void printAddDishMessage(Dish dish) {
String dishNameString = "Dish Name: " + dish.getName();
- String dishPriceString = "Dish Price: $" + dish.getPrice();
+ DecimalFormat dollarValue = new DecimalFormat("0.00");
+ float dishPrice = dish.getPrice();
+ String dishPriceString = "Dish Price: $" + dollarValue.format(dishPrice);
StringBuilder dishIngredientsString = new StringBuilder("Ingredients:\n");
for (int i = 0; i < dish.getIngredients().size(); i++) {
From bafeabf2525e5166b1ab60cb4f14a6fc7566bf58 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 20:32:17 +0800
Subject: [PATCH 121/870] Resolve checkstyle errors
---
.../java/seedu/cafectrl/parser/Parser.java | 22 +++++++++++--------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index b34cae1d56..c82e26b821 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -28,14 +28,8 @@ public class Parser {
public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+) (?.*)");
// Command Argument Patterns
- private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) "
- + "price/([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))? "
- + "(ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+"
- + "(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)";
- private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
- private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
- private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
- public static final String INGREDIENT_ARGUMENT_STRING = "ingredient/(?[A-Za-z0-9\\s]+) qty/(?[A-Za-z0-9\\s]+)";
+ public static final String INGREDIENT_ARGUMENT_STRING = "ingredient/(?[A-Za-z0-9\\s]+) "
+ + "qty/(?[A-Za-z0-9\\s]+)";
public static final String INGREDIENT_DIVIDER_REGEX = ", ";
public static final String INGREDIENT_DIVIDER_STRING = ",";
public static final String INGREDIENT_NAME_REGEX_GROUP_LABEL = "name";
@@ -43,6 +37,14 @@ public class Parser {
public static final int DISH_NAME_MATCHER_GROUP_NUM = 1;
public static final int PRICE_MATCHER_GROUP_NUM = 2;
public static final int INGREDIENT_LIST_MATCHER_GROUP_NUM = 4;
+ private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) "
+ + "price/([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))? "
+ + "(ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+"
+ + "(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)";
+ private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
+ private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
+ private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
+
/**
* Parse userInput and group it under commandWord and arguments
@@ -143,7 +145,9 @@ private static Command prepareAdd(String arguments) {
ArrayList ingredients = new ArrayList<>();
IncorrectCommand incorrectCommand = ingredientParsing(ingredientsListString, ingredients);
- if (incorrectCommand != null) return incorrectCommand;
+ if (incorrectCommand != null) {
+ return incorrectCommand;
+ }
Dish dish = new Dish(dishName, ingredients, price);
From 908e1da4fe7c6f257b299d05d81fc277440ff8cc Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 20:32:48 +0800
Subject: [PATCH 122/870] EditPriceCommandTest.ava: add JUnit test for valid
input
---
src/main/java/seedu/cafectrl/ui/Ui.java | 3 +-
.../command/EditPriceCommandTest.java | 42 +++++++++++++++++++
2 files changed, 43 insertions(+), 2 deletions(-)
create mode 100644 src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 2983643416..e8d2888226 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -96,7 +96,6 @@ public void showToUser(String... message) {
* @param menuItem menuItem that has been modified
*/
public void showEditPriceMessage(String menuItem) {
- System.out.println(Messages.PRICE_MODIFIED_MESSAGE);
- this.showToUser(menuItem);
+ this.showToUser(Messages.PRICE_MODIFIED_MESSAGE, menuItem);
}
}
diff --git a/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
new file mode 100644
index 0000000000..add45d5011
--- /dev/null
+++ b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
@@ -0,0 +1,42 @@
+package seedu.cafectrl.command;
+
+import org.junit.jupiter.api.Test;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Messages;
+import seedu.cafectrl.ui.Ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class EditPriceCommandTest {
+
+ @Test
+ void execute_validInput_editPrice() {
+ Menu menu = new Menu();
+ Dish testDish = new Dish("Chicken Rice", 2.50F);
+ menu.addDish(testDish);
+
+ ArrayList actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ int testDishIndex = 1;
+ float testNewPrice = 3;
+ Command editPriceCommand = new EditPriceCommand(testDishIndex, testNewPrice);
+ editPriceCommand.execute(menu, ui);
+
+ int firstLine = 0;
+ int secondLine = 1;
+ String expectedOutputFirstLine = Messages.PRICE_MODIFIED_MESSAGE;
+ String expectedOutputSecondLine = testDish.toString();
+ assertEquals(expectedOutputFirstLine, actualOutput.get(firstLine));
+ assertEquals(expectedOutputSecondLine, actualOutput.get(secondLine));
+ }
+}
\ No newline at end of file
From dc474694da89328e8858e7a6d0dbd9e3acecd725 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 20:43:31 +0800
Subject: [PATCH 123/870] Fix regex for checking command format
---
src/main/java/seedu/cafectrl/parser/Parser.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index c82e26b821..a30123aaaf 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -25,7 +25,7 @@
* into a format that can be interpreted by other core classes
*/
public class Parser {
- public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+) (?.*)");
+ public static final Pattern COMMAND_ARGUMENT_FORMAT = Pattern.compile("(?\\S+)\\s?(?.*)");
// Command Argument Patterns
public static final String INGREDIENT_ARGUMENT_STRING = "ingredient/(?[A-Za-z0-9\\s]+) "
From 7f6ae576969e353434ae08a9b55ead58169bb6f0 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 20:48:36 +0800
Subject: [PATCH 124/870] ParserTest.java: add JUnit test for
parseCommand_unrecognisedInput_unknownCommand
---
.../java/seedu/cafectrl/parser/Parser.java | 7 ++--
.../seedu/cafectrl/parser/ParserTest.java | 32 +++++++++++++++++++
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index edc4d0ed7d..1b79509795 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -85,6 +85,7 @@ private static Command prepareEditListCommand(String arguments) {
/**
* Parse argument in the context of edit price command
+ * @param menu menu of the current session
* @param arguments string that matches group arguments
* @return new EditDishCommand
*/
@@ -98,8 +99,10 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments) {
}
try {
- int dishIndex = Integer.parseInt(matcher.group(1));
- float newPrice = Float.parseFloat(matcher.group(2));
+ int dishIndexGroup = 1;
+ int newPriceGroup = 2;
+ int dishIndex = Integer.parseInt(matcher.group(dishIndexGroup));
+ float newPrice = Float.parseFloat(matcher.group(newPriceGroup));
// Check whether the dish index is valid
if (!menu.isValidDishIndex(dishIndex)) {
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 56cc60f428..422ddd5ad6 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -1,8 +1,40 @@
package seedu.cafectrl.parser;
+import org.junit.jupiter.api.Test;
+import seedu.cafectrl.command.Command;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Messages;
+import seedu.cafectrl.ui.Ui;
+import seedu.cafectrl.ui.UserOutput;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* Junit test for Parser.java
*/
class ParserTest {
+ @Test
+ void parseCommand_unrecognisedInput_unknownCommand () {
+ Menu menu = new Menu();
+ Dish testDish = new Dish("Chicken Rice", 2.50F);
+ menu.addDish(testDish);
+ String testUserInput = "random input";
+
+ ArrayList actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ Command commandReturned = Parser.parseCommand(menu, testUserInput);
+ commandReturned.execute(menu, ui);
+ assertEquals(UserOutput.UNKNOWN_COMMAND_MESSAGE.message, actualOutput.get(0));
+ }
}
From a20cbd574d66169d6c7098cc9edeffbadefbf04d Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Wed, 18 Oct 2023 21:01:01 +0800
Subject: [PATCH 125/870] ParserTest.java: add JUnit test for possible user
inputs for edit_price command
---
.../command/EditPriceCommandTest.java | 2 +-
.../seedu/cafectrl/parser/ParserTest.java | 42 ++++++++++++++++++-
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
index add45d5011..f9061520cc 100644
--- a/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
@@ -39,4 +39,4 @@ public void showToUser(String... message) {
assertEquals(expectedOutputFirstLine, actualOutput.get(firstLine));
assertEquals(expectedOutputSecondLine, actualOutput.get(secondLine));
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 422ddd5ad6..0242f85c56 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -19,7 +19,7 @@
class ParserTest {
@Test
- void parseCommand_unrecognisedInput_unknownCommand () {
+ void parseCommand_unrecognisedInput_unknownCommand() {
Menu menu = new Menu();
Dish testDish = new Dish("Chicken Rice", 2.50F);
menu.addDish(testDish);
@@ -37,4 +37,44 @@ public void showToUser(String... message) {
commandReturned.execute(menu, ui);
assertEquals(UserOutput.UNKNOWN_COMMAND_MESSAGE.message, actualOutput.get(0));
}
+
+ @Test
+ void parseCommand_missingArgumentsForEditPrice_missingArgMsg() {
+ Menu menu = new Menu();
+ Dish testDish = new Dish("Chicken Rice", 2.50F);
+ menu.addDish(testDish);
+ String testUserInput = "edit_price index/1";
+
+ ArrayList actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ Command commandReturned = Parser.parseCommand(menu, testUserInput);
+ commandReturned.execute(menu, ui);
+ assertEquals(Messages.MISSING_ARGUMENT_FOR_EDIT_PRICE, actualOutput.get(0));
+ }
+
+ @Test
+ void parseCommand_invalidDishIndexForEditPrice_invalidIndexForEditPrice() {
+ Menu menu = new Menu();
+ Dish testDish = new Dish("Chicken Rice", 2.50F);
+ menu.addDish(testDish);
+ String testUserInput = "edit_price index/2 price/3";
+
+ ArrayList actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ Command commandReturned = Parser.parseCommand(menu, testUserInput);
+ commandReturned.execute(menu, ui);
+ assertEquals(Messages.INVALID_DISH_INDEX, actualOutput.get(0));
+ }
}
From 4d15f13e7ddfa5613ca9aeead0a522e7ca345d7d Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 21:11:19 +0800
Subject: [PATCH 126/870] Migrate code to the proper file to account for
refactoring
---
.../cafectrl/command/AddDishCommandTest.java | 25 +++++++++++++++
.../duke/command/AddDishCommandTest.java | 31 -------------------
2 files changed, 25 insertions(+), 31 deletions(-)
delete mode 100644 src/test/java/seedu/duke/command/AddDishCommandTest.java
diff --git a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
index ec5f75ec92..2f6e27e964 100644
--- a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
@@ -1,5 +1,30 @@
package seedu.cafectrl.command;
+import org.junit.jupiter.api.Test;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.data.dish.Ingredient;
+import seedu.cafectrl.ui.Ui;
+
+import java.util.ArrayList;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
class AddDishCommandTest {
+ @Test
+ void execute_dishAdded_expectDishInMenu() {
+ ArrayList ingredients = new ArrayList<>();
+ ArrayList menuItems = new ArrayList<>();
+ Menu menu = new Menu(menuItems);
+ Ui ui = new Ui();
+ //creating a dish
+ ingredients.add(new Ingredient("chicken", "100g"));
+ Dish dish = new Dish("Chicken Rice", ingredients, (float) 1.00);
+
+ AddDishCommand addDishCommand = new AddDishCommand(dish);
+
+ addDishCommand.execute(menu, ui);
+ assertEquals(1, menu.getMenuItemsList().size());
+ }
}
diff --git a/src/test/java/seedu/duke/command/AddDishCommandTest.java b/src/test/java/seedu/duke/command/AddDishCommandTest.java
deleted file mode 100644
index 159914a003..0000000000
--- a/src/test/java/seedu/duke/command/AddDishCommandTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package seedu.duke.command;
-
-import org.junit.jupiter.api.Test;
-import seedu.cafectrl.command.AddDishCommand;
-import seedu.cafectrl.data.Menu;
-import seedu.cafectrl.data.dish.Dish;
-import seedu.cafectrl.data.dish.Ingredient;
-import seedu.cafectrl.ui.Ui;
-
-import java.util.ArrayList;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-class AddDishCommandTest {
- @Test
- void execute_dishAdded_expectDishInMenu() {
- ArrayList ingredients = new ArrayList<>();
- ArrayList menuItems = new ArrayList<>();
- Menu menu = new Menu(menuItems);
- Ui ui = new Ui();
- //creating a dish
- ingredients.add(new Ingredient("chicken", "100g"));
- Dish dish = new Dish("Chicken Rice", ingredients, (float) 1.00);
-
- AddDishCommand addDishCommand = new AddDishCommand(dish);
-
- addDishCommand.execute(menu, ui);
-
- assertEquals(1, menu.getMenuItemsList().size());
- }
-}
From 21f12ca05d6c12e1ebf594b645ee414aa463f867 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 21:17:57 +0800
Subject: [PATCH 127/870] Rename assertion test class
---
src/test/java/seedu/cafectrl/command/AddDishCommandTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
index 2f6e27e964..23e5f73d45 100644
--- a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
@@ -12,7 +12,7 @@
class AddDishCommandTest {
@Test
- void execute_dishAdded_expectDishInMenu() {
+ void execute_oneDishAdded_expectDishInMenu() {
ArrayList ingredients = new ArrayList<>();
ArrayList menuItems = new ArrayList<>();
Menu menu = new Menu(menuItems);
From 40341fbba23130d1bb37d570eabbe1422bcf451b Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 21:24:34 +0800
Subject: [PATCH 128/870] Throw Index Out Of Bounds Exception
---
src/main/java/seedu/cafectrl/command/DeleteDishCommand.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
index d615c4e0f1..7000aad19c 100644
--- a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
@@ -28,6 +28,7 @@ public void execute(Menu menu, Ui ui) {
menu.removeDish(index);
} catch (IndexOutOfBoundsException e) {
ui.showToUser(INVALID_INDEX_MESSAGE);
+ throw new IndexOutOfBoundsException();
}
}
}
From aca573016cb7a28d67fb0cb705e45fe9f562d15f Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 21:25:07 +0800
Subject: [PATCH 129/870] Update prepareDelete to match other methods
---
src/main/java/seedu/cafectrl/parser/Parser.java | 17 ++++++++++++-----
src/main/java/seedu/cafectrl/ui/Messages.java | 4 ++++
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index c2de427150..0b9f6f8e3e 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -176,15 +176,22 @@ private static Command prepareListIngredient(String userInput) {
/**
* Parses arguments in the context of the Delete command.
*
- * @param userInput Input from the user
+ * @param arguments Input from the user
* @return Command to be executed
*/
- private static Command prepareDelete(String userInput) {
+ private static Command prepareDelete(String arguments) {
+ Pattern deleteDishArgumentsPattern = Pattern.compile(DELETE_ARGUMENT_STRING);
+ Matcher matcher = deleteDishArgumentsPattern.matcher(arguments.trim());
+
+ // Checks whether the overall pattern of delete price arguments is correct
+ if (!matcher.matches()) {
+ return new IncorrectCommand(Messages.MISSING_ARGUMENT_FOR_DELETE);
+ }
+
try {
- final int listIndex = parseArgsAsDisplayedIndex(userInput, DeleteDishCommand.COMMAND_WORD);
+ int listIndexArgGroup = 1;
+ int listIndex = Integer.parseInt(matcher.group(listIndexArgGroup));
return new DeleteDishCommand(listIndex);
- } catch (ParseException e) {
- return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE);
} catch (NumberFormatException nfe) {
return new IncorrectCommand("MESSAGE_INVALID_TASK_DISPLAYED_INDEX");
}
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 03b7ff3feb..9821a6c847 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -5,6 +5,10 @@ public class Messages {
// Error messages
public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments "
+ "for edit price command.";
+
+ public static final String MISSING_ARGUMENT_FOR_DELETE = "Error: Missing arguments "
+ + "for delete command.";
+
public static final String INVALID_DISH_INDEX = "Hmmm, can you double the your dish index, "
+ "I can't seem to find the dish you're referring to";
public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me "
From eed4152ad902aee18c1690be1c2b8e5d1264823a Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 21:25:44 +0800
Subject: [PATCH 130/870] Assert exception instead of equal string
---
.../command/DeleteDishCommandTest.java | 25 ++++++-------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
index 01dc841e39..2850bb814c 100644
--- a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
@@ -10,13 +10,13 @@
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
class DeleteDishCommandTest {
@Test
- void execute_validInput() throws Exception {
- ArrayList menuItems = new ArrayList<>();
- Menu menu = new Menu(menuItems);
+ void execute_validInput() {
+ Menu menu = new Menu();
menu.addDish(new Dish("Chicken Rice", 2.50F));
menu.addDish(new Dish("Chicken Curry", 4.30F));
menu.addDish(new Dish("Nasi Lemak", 5.60F));
@@ -39,27 +39,16 @@ public void showToUser(String... message) {
}
@Test
- void execute_invalidInput() throws Exception {
- ArrayList menuItems = new ArrayList<>();
- Menu menu = new Menu(menuItems);
+ void execute_invalidInput_throwIndexOutOfBoundsException() {
+ Menu menu = new Menu();
menu.addDish(new Dish("Chicken Rice", 2.50F));
menu.addDish(new Dish("Chicken Curry", 4.30F));
menu.addDish(new Dish("Nasi Lemak", 5.60F));
- ArrayList actualOutput = new ArrayList<>();
- Ui ui = new Ui() {
- @Override
- public void showToUser(String... message) {
- actualOutput.addAll(Arrays.asList(message));
- }
- };
-
+ Ui ui = new Ui();
int testIndex = 5;
DeleteDishCommand deleteDishCommand = new DeleteDishCommand(testIndex);
- deleteDishCommand.execute(menu, ui);
- int actualOutputIndex = 0;
- String expectedOutput = "Please select a valid dish index :)";
- assertEquals(expectedOutput, actualOutput.get(actualOutputIndex));
+ assertThrows(IndexOutOfBoundsException.class, () -> deleteDishCommand.execute(menu, ui));
}
}
From 7f02a0de9aac1ed99944fc0c4beebc648b1d7d60 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 21:26:26 +0800
Subject: [PATCH 131/870] Create JUnit test for prepareDelete in Parser class
---
.../java/seedu/cafectrl/parser/ParserTest.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 56cc60f428..9402fd4405 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -1,8 +1,25 @@
package seedu.cafectrl.parser;
+import org.junit.jupiter.api.Test;
+import seedu.cafectrl.command.Command;
+import seedu.cafectrl.command.IncorrectCommand;
+import seedu.cafectrl.data.Menu;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* Junit test for Parser.java
*/
class ParserTest {
+ @Test
+ void parseCommand_missingArg_returnIncorrectCommandObject() {
+ Menu menu = new Menu();
+
+ String fullUserInput = "delete";
+ Command command = Parser.parseCommand(menu, fullUserInput);
+
+ assertEquals(IncorrectCommand.class, command.getClass());
+ }
+
}
From 4d0cc8da2c44626b3abdc3baaac5f28f183e57bc Mon Sep 17 00:00:00 2001
From: ZH
Date: Wed, 18 Oct 2023 22:16:16 +0800
Subject: [PATCH 132/870] Update JUnit assertion use
---
.../cafectrl/command/ListMenuCommand.java | 2 +-
.../cafectrl/command/ListMenuCommandTest.java | 28 ++++++++++++++++++-
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index af2584c8c6..cf72fd8a53 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -27,7 +27,7 @@ public void execute(Menu menu, Ui ui) {
String indexNum = String.valueOf(i+1);
String dishName = menu.getDish(i).getName();
String dishPrice = dollarValue.format(menu.getDish(i).getPrice());
- ui.showToUser(indexNum + "." + dishName + " $" + dishPrice);
+ ui.showToUser(indexNum + ". " + dishName + " $" + dishPrice);
}
};
}
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index 94a2ba2f49..c8f538be52 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -18,7 +18,33 @@ public void execute_addTwoDishes_expectTwoDishes() {
Menu menu = new Menu(menuItems);
assertEquals(2, menu.getSize());
+ ArrayList commandOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ String parseString = convertArrayToString(message, ",");
+ commandOutput.add(parseString);
+ }
+ };
+
Command listMenuCommand = new ListMenuCommand();
- listMenuCommand.execute(menu, new Ui());
+ listMenuCommand.execute(menu, ui);
+
+ String actualOutput = String.join(", ", commandOutput);
+
+ String expectedOutput = "Ah, behold, the grand menu of delights!" +
+ " 1. Chicken Rice $2.50" +
+ " 2. Chicken Curry $4.30";
+
+ assertEquals(expectedOutput.trim().replaceAll(", ", " "),
+ actualOutput.trim().replaceAll(", ", " "));
+ }
+
+ private static String convertArrayToString(String[] message, String delimiter) {
+ StringBuilder sb = new StringBuilder();
+ for (String str : message) {
+ sb.append(str.toString()).append(delimiter);
+ }
+ return sb.substring(0, sb.length() -1);
}
}
From 37824dd4fbe3a1a7651fa68e34755eedfb2d726d Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Wed, 18 Oct 2023 22:18:10 +0800
Subject: [PATCH 133/870] Update parsing of List Ingredients command.
Fixes #15
---
.../java/seedu/cafectrl/command/Command.java | 2 +-
.../command/ListIngredientCommand.java | 3 ++-
.../java/seedu/cafectrl/parser/Parser.java | 27 ++++++++++++-------
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/Command.java b/src/main/java/seedu/cafectrl/command/Command.java
index aec67d413b..f808b55dca 100644
--- a/src/main/java/seedu/cafectrl/command/Command.java
+++ b/src/main/java/seedu/cafectrl/command/Command.java
@@ -8,7 +8,7 @@
*/
public class Command {
- protected int index;
+ public int index;
public void setIndex(int index) {
this.index = index;
diff --git a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
index 56086db081..e5c13ce31e 100644
--- a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
@@ -2,6 +2,7 @@
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
/**
@@ -24,7 +25,7 @@ public void execute(Menu menu, Ui ui) {
Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
ui.printIngredients(selectedDish);
} catch (IndexOutOfBoundsException e) {
- throw new IllegalArgumentException("Invalid dish index");
+ throw new IllegalArgumentException(Messages.INVALID_DISH_INDEX);
}
}
}
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index c2de427150..8fd6f1e993 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -58,7 +58,7 @@ public static Command parseCommand(Menu menu, String userInput) {
return prepareDelete(arguments);
case ListIngredientCommand.COMMAND_WORD:
- return prepareListIngredient(arguments);
+ return prepareListIngredient(menu, arguments);
case ListMenuCommand.COMMAND_WORD:
return prepareListMenu();
@@ -159,18 +159,25 @@ private static Command prepareAdd(String arguments) {
/**
* Parses arguments in the context of the ListIngredient command.
- * @param userInput arguments string to parse as index number
+ * @param menu menu of the current session
+ * @param arguments string that matches group arguments
* @return the prepared command
*/
- private static Command prepareListIngredient(String userInput) {
- try {
- final int listIndex = parseArgsAsDisplayedIndex(userInput, ListIngredientCommand.COMMAND_WORD);
- return new ListIngredientCommand(listIndex);
- } catch (ParseException e) {
- return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + ListIngredientCommand.MESSAGE_USAGE);
- } catch (NumberFormatException nfe) {
- return new IncorrectCommand("MESSAGE_INVALID_TASK_DISPLAYED_INDEX");
+ private static Command prepareListIngredient(Menu menu, String arguments) {
+ final Pattern prepareListPattern = Pattern.compile(LIST_INGREDIENTS_ARGUMENT_STRING);
+ Matcher matcher = prepareListPattern.matcher(arguments.trim());
+
+ if (!matcher.matches()) {
+ return new IncorrectCommand(Messages.MISSING_ARGUMENT_FOR_LIST_INGREDIENTS);
}
+
+ int dishIndex = Integer.parseInt(matcher.group(1));
+
+ if (!menu.isValidDishIndex(dishIndex)) {
+ return new IncorrectCommand(Messages.INVALID_DISH_INDEX);
+ }
+
+ return new ListIngredientCommand(dishIndex);
}
/**
From f3cc35239cedc9d46cb877ebe130fd7b47d1627d Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Wed, 18 Oct 2023 22:18:32 +0800
Subject: [PATCH 134/870] Implement JUnit test for parsing list ingredients
command.
Fixes #15
---
src/main/java/seedu/cafectrl/ui/Messages.java | 10 +--
.../seedu/cafectrl/parser/ParserTest.java | 74 +++++++++++++++++++
2 files changed, 79 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 03b7ff3feb..1c1d84543a 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -5,13 +5,13 @@ public class Messages {
// Error messages
public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments "
+ "for edit price command.";
- public static final String INVALID_DISH_INDEX = "Hmmm, can you double the your dish index, "
- + "I can't seem to find the dish you're referring to";
- public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Oops, seems like you gave me "
- + "the wrong type for dish index "
- + "or price. Make sure dish index is "
+ public static final String INVALID_DISH_INDEX = "Error: Invalid dish index.";
+ public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Error: Invalid dish index. \n Make sure dish index is "
+ "of type int and price is of type float!";
// Ui messages
public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
+
+ public static final String MISSING_ARGUMENT_FOR_LIST_INGREDIENTS = "Error: Missing arguments "
+ + "for list ingredients command.";
}
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 56cc60f428..5562dc6ae2 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -1,8 +1,82 @@
package seedu.cafectrl.parser;
+import org.junit.jupiter.api.Test;
+import seedu.cafectrl.command.Command;
+import seedu.cafectrl.command.IncorrectCommand;
+import seedu.cafectrl.command.ListIngredientCommand;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.data.dish.Ingredient;
+import seedu.cafectrl.ui.Messages;
+import seedu.cafectrl.ui.Ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
/**
* Junit test for Parser.java
*/
class ParserTest {
+ @Test
+ public void parseCommand_validCommand_successfulCommandParse() {
+ ArrayList menuItems = new ArrayList<>();
+ menuItems.add(new Dish("Chicken Rice",
+ new ArrayList<>(Arrays.asList(new Ingredient("Rice", "1 cup"),
+ new Ingredient("Chicken", "100g"))), 8.0F));
+ menuItems.add(new Dish("Chicken Sandwich",
+ new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "100g"),
+ new Ingredient("Chicken", "50g"))), 5.0F));
+ Menu menu = new Menu(menuItems);
+
+ String userInput = "list_ingredients 1";
+ Command result = Parser.parseCommand(menu, userInput);
+
+ assertTrue(result instanceof ListIngredientCommand);
+
+ ListIngredientCommand listIngredientCommand = (ListIngredientCommand) result;
+ int index = listIngredientCommand.index;
+ assertEquals(1, index);
+ }
+
+ @Test
+ public void parseCommand_missingIndex_returnsErrorMessage() {
+ Menu menu = new Menu();
+ String userInput = "list_ingredients";
+ Command result = Parser.parseCommand(menu, userInput);
+
+ assertTrue(result instanceof IncorrectCommand);
+
+ IncorrectCommand incorrectCommand = (IncorrectCommand) result;
+ String feedbackToUser = incorrectCommand.feedbackToUser;
+ assertEquals(Messages.MISSING_ARGUMENT_FOR_LIST_INGREDIENTS, feedbackToUser);
+ }
+
+ @Test
+ public void parseCommand_invalidIndex_returnsErrorMessage() {
+ Menu menu = new Menu();
+ String userInput = "list_ingredients a";
+ Command result = Parser.parseCommand(menu, userInput);
+
+ assertTrue(result instanceof IncorrectCommand);
+
+ IncorrectCommand incorrectCommand = (IncorrectCommand) result;
+ String feedbackToUser = incorrectCommand.feedbackToUser;
+ assertEquals(Messages.MISSING_ARGUMENT_FOR_LIST_INGREDIENTS, feedbackToUser);
+ }
+
+ @Test
+ public void parseCommand_indexOutOfBounds_returnsErrorMessage() {
+ Menu menu = new Menu();
+ String userInput = "list_ingredients 1";
+ Command result = Parser.parseCommand(menu, userInput);
+
+ assertTrue(result instanceof IncorrectCommand);
+ IncorrectCommand incorrectCommand = (IncorrectCommand) result;
+ String feedbackToUser = incorrectCommand.feedbackToUser;
+ assertEquals(Messages.INVALID_DISH_INDEX, feedbackToUser);
+ }
}
From 5b7fa6298201506cb8947488d2bcfd94d02210a6 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Wed, 18 Oct 2023 22:26:55 +0800
Subject: [PATCH 135/870] Improve coding standard using line wrapping.
---
src/main/java/seedu/cafectrl/ui/Messages.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 1c1d84543a..c9aa95dd80 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -6,7 +6,8 @@ public class Messages {
public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments "
+ "for edit price command.";
public static final String INVALID_DISH_INDEX = "Error: Invalid dish index.";
- public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Error: Invalid dish index. \n Make sure dish index is "
+ public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Error: Invalid dish index. \n "
+ + "Make sure dish index is "
+ "of type int and price is of type float!";
// Ui messages
From 0956546fb4a59b7037ad7a3e659dc894f97ef3dc Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Wed, 18 Oct 2023 22:29:49 +0800
Subject: [PATCH 136/870] Update ListMenuCommandTest.java
---
.../java/seedu/cafectrl/command/ListMenuCommandTest.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index c8f538be52..0676df8d72 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -32,9 +32,9 @@ public void showToUser(String... message) {
String actualOutput = String.join(", ", commandOutput);
- String expectedOutput = "Ah, behold, the grand menu of delights!" +
- " 1. Chicken Rice $2.50" +
- " 2. Chicken Curry $4.30";
+ String expectedOutput = "Ah, behold, the grand menu of delights!"
+ + " 1. Chicken Rice $2.50"
+ + " 2. Chicken Curry $4.30";
assertEquals(expectedOutput.trim().replaceAll(", ", " "),
actualOutput.trim().replaceAll(", ", " "));
@@ -45,6 +45,6 @@ private static String convertArrayToString(String[] message, String delimiter) {
for (String str : message) {
sb.append(str.toString()).append(delimiter);
}
- return sb.substring(0, sb.length() -1);
+ return sb.substring(0, sb.length() - 1);
}
}
From 293c66243dde702314e4b2f53db72f638f5a773b Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 22:36:30 +0800
Subject: [PATCH 137/870] Added JUnit Tests for add dish command parsing
---
.../seedu/cafectrl/parser/ParserTest.java | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 0242f85c56..1f228e696c 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.parser;
import org.junit.jupiter.api.Test;
+import seedu.cafectrl.command.AddDishCommand;
import seedu.cafectrl.command.Command;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
@@ -12,6 +13,8 @@
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Junit test for Parser.java
@@ -77,4 +80,36 @@ public void showToUser(String... message) {
commandReturned.execute(menu, ui);
assertEquals(Messages.INVALID_DISH_INDEX, actualOutput.get(0));
}
+
+ @Test
+ void parseCommand_validDishInputForAddDish_dishAddedToMenu() {
+ Menu menu = new Menu();
+ Ui ui = new Ui();
+ String testDishInputWithOneIngredient = "add name/Christmas Ham price/50.00 ingredient/Ham qty/1kg";
+ Command outputCommand = Parser.parseCommand(menu, testDishInputWithOneIngredient);
+ //Test for correct Command type returned
+ assertTrue(outputCommand instanceof AddDishCommand);
+ //Test for 1 Dish added to Menu
+ outputCommand.execute(menu, ui);
+ assertEquals(1, menu.getSize());
+ //Test for correct parsing of dish arguments
+ Dish getOutputDish = menu.getDish(0);
+ assertEquals("Christmas Ham", getOutputDish.getName()); // Dish name test
+ assertEquals((float) 50.0, getOutputDish.getPrice()); //Dish price test
+ assertEquals("[Ham - 1kg]", getOutputDish.getIngredients().toString()); //Dish ingredients test
+ }
+
+ @Test
+ void parseCommand_invalidDishInputForAddDish_noDishAddedToMenu() {
+ Menu menu = new Menu();
+ Ui ui = new Ui();
+ //input name/ argument wrongly
+ String testDishInputWithOneIngredient = "add named/Christmas Ham price/50.00 ingredient/Ham qty/1kg";
+ Command outputCommand = Parser.parseCommand(menu, testDishInputWithOneIngredient);
+ //Test for incorrect Command type returned
+ assertFalse(outputCommand instanceof AddDishCommand);
+ //Test for no dish added in menu
+ outputCommand.execute(menu, ui);
+ assertEquals(0, menu.getSize());
+ }
}
From 4881d95845ceae0c637849d3fa0142af1402db66 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 22:39:51 +0800
Subject: [PATCH 138/870] Use message string from Messages class
---
src/main/java/seedu/cafectrl/command/DeleteDishCommand.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
index 7000aad19c..759b3915ba 100644
--- a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
@@ -2,6 +2,7 @@
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
/**
@@ -10,7 +11,7 @@
public class DeleteDishCommand extends Command {
public static final String COMMAND_WORD = "delete";
- public static final String INVALID_INDEX_MESSAGE = "Please select a valid dish index :)";
+
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the menu item identified by the index number used in the last menu listing.\n"
+ "Parameters: INDEX\n"
@@ -27,7 +28,7 @@ public void execute(Menu menu, Ui ui) {
ui.showDeleteMessage(selectedDish);
menu.removeDish(index);
} catch (IndexOutOfBoundsException e) {
- ui.showToUser(INVALID_INDEX_MESSAGE);
+ ui.showToUser(Messages.INVALID_DISH_INDEX);
throw new IndexOutOfBoundsException();
}
}
From 695a304ae83f3e437f8ad2ed792591a1a624f2f6 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 22:40:27 +0800
Subject: [PATCH 139/870] Update prepareDelete method to standardize
---
.../java/seedu/cafectrl/parser/Parser.java | 22 ++++++++++---------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 51ecc7bdef..6b1f070eea 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -69,7 +69,7 @@ public static Command parseCommand(Menu menu, String userInput) {
return prepareAdd(arguments);
case DeleteDishCommand.COMMAND_WORD:
- return prepareDelete(arguments);
+ return prepareDelete(menu, arguments);
case ListIngredientCommand.COMMAND_WORD:
return prepareListIngredient(arguments);
@@ -209,10 +209,11 @@ private static Command prepareListIngredient(String userInput) {
/**
* Parses arguments in the context of the Delete command.
*
- * @param arguments Input from the user
- * @return Command to be executed
+ * @param menu menu of the current session
+ * @param arguments string that matches group arguments
+ * @return DeleteDishCommand if command is valid, IncorrectCommand otherwise
*/
- private static Command prepareDelete(String arguments) {
+ private static Command prepareDelete(Menu menu, String arguments) {
Pattern deleteDishArgumentsPattern = Pattern.compile(DELETE_ARGUMENT_STRING);
Matcher matcher = deleteDishArgumentsPattern.matcher(arguments.trim());
@@ -221,13 +222,14 @@ private static Command prepareDelete(String arguments) {
return new IncorrectCommand(Messages.MISSING_ARGUMENT_FOR_DELETE);
}
- try {
- int listIndexArgGroup = 1;
- int listIndex = Integer.parseInt(matcher.group(listIndexArgGroup));
- return new DeleteDishCommand(listIndex);
- } catch (NumberFormatException nfe) {
- return new IncorrectCommand("MESSAGE_INVALID_TASK_DISPLAYED_INDEX");
+ int listIndexArgGroup = 1;
+ int dishIndex = Integer.parseInt(matcher.group(listIndexArgGroup));
+
+ if (!menu.isValidDishIndex(dishIndex)) {
+ return new IncorrectCommand(Messages.INVALID_DISH_INDEX);
}
+
+ return new DeleteDishCommand(dishIndex);
}
/**
From cdea65514d1e4bc676cec5623e13bc10b96da8b3 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 22:41:03 +0800
Subject: [PATCH 140/870] Add JUnit test for delete command for parseCommand
method
---
.../seedu/cafectrl/parser/ParserTest.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 4c9a8298b1..316c059cdc 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -2,6 +2,7 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.command.Command;
+import seedu.cafectrl.command.DeleteDishCommand;
import seedu.cafectrl.command.IncorrectCommand;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
@@ -20,15 +21,25 @@
class ParserTest {
@Test
- void parseCommand_missingArg_returnIncorrectCommandObject() {
+ void parseCommand_missingArgumentForDelete_emptyArgMessage() {
Menu menu = new Menu();
- String fullUserInput = "delete";
- Command command = Parser.parseCommand(menu, fullUserInput);
+ String testUserInput = "delete";
+ ArrayList actualOutput = new ArrayList<>();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
- assertEquals(IncorrectCommand.class, command.getClass());
+ int actualOutputIndex = 0;
+ Command commandReturned = Parser.parseCommand(menu, testUserInput);
+ commandReturned.execute(menu, ui);
+ assertEquals(Messages.MISSING_ARGUMENT_FOR_DELETE, actualOutput.get(actualOutputIndex));
}
+
@Test
void parseCommand_unrecognisedInput_unknownCommand() {
Menu menu = new Menu();
From 41cb964a10164e5c327493bac64d1bb053d05657 Mon Sep 17 00:00:00 2001
From: Dexter <35828587+DextheChik3n@users.noreply.github.com>
Date: Wed, 18 Oct 2023 23:02:34 +0800
Subject: [PATCH 141/870] Update ParserTest.java to resolve checkstyle bug
---
src/test/java/seedu/cafectrl/parser/ParserTest.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 28ff36008d..5196fa9f5c 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -19,7 +19,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Junit test for Parser.java
From 72da852206244ef87bcd8f2f765de519177317d0 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 23:05:30 +0800
Subject: [PATCH 142/870] Improve code quality
Fixes #17
---
src/main/java/seedu/cafectrl/command/DeleteDishCommand.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
index 02512f8ff1..a42f9b1eff 100644
--- a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
@@ -24,10 +24,10 @@ public DeleteDishCommand(int listIndex) {
@Override
public void execute(Menu menu, Ui ui) {
try {
- int dishToBeDeleted = index - Ui.OFFSET_LIST_INDEX;
- Dish selectedDish = menu.getMenuItemsList().get(dishToBeDeleted);
+ int dishIndexToBeDeleted = index - Ui.OFFSET_LIST_INDEX;
+ Dish selectedDish = menu.getMenuItemsList().get(dishIndexToBeDeleted);
ui.showDeleteMessage(selectedDish);
- menu.removeDish(dishToBeDeleted);
+ menu.removeDish(dishIndexToBeDeleted);
} catch (IndexOutOfBoundsException e) {
ui.showToUser(Messages.INVALID_DISH_INDEX);
throw new IndexOutOfBoundsException();
From d2c8fd89be220ad3d1ddf9ce4f4e2a0f734dc9c0 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Wed, 18 Oct 2023 23:09:54 +0800
Subject: [PATCH 143/870] Remove duplicate import statement
---
src/test/java/seedu/cafectrl/parser/ParserTest.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 1af999abbb..38b90b971d 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -3,8 +3,6 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.command.Command;
import seedu.cafectrl.command.DeleteDishCommand;
-import seedu.cafectrl.command.IncorrectCommand;
-
import seedu.cafectrl.command.IncorrectCommand;
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.data.Menu;
From e43dffdab7af41343dd985321360c9d9547d0ff3 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Wed, 18 Oct 2023 23:16:00 +0800
Subject: [PATCH 144/870] Update MenuList appearance
---
.../java/seedu/cafectrl/command/ListMenuCommand.java | 6 ++++--
src/main/java/seedu/cafectrl/ui/Ui.java | 11 +++++++++++
src/main/java/seedu/cafectrl/ui/UserOutput.java | 4 ++++
.../seedu/cafectrl/command/ListMenuCommandTest.java | 8 ++++----
4 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index cf72fd8a53..8f7df7ea4f 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -22,12 +22,14 @@ public class ListMenuCommand extends Command {
*/
@Override
public void execute(Menu menu, Ui ui) {
- ui.showToUser(UserOutput.LIST_MESSAGE.message);
+ ui.showToUser(UserOutput.MENU_TOP.message, UserOutput.LIST_MESSAGE_MENU.message, UserOutput.MENU_CORNER.message, UserOutput.MENU_TITLE.message, UserOutput.MENU_CORNER.message);
for(int i =0; i < menu.getSize(); i++) {
String indexNum = String.valueOf(i+1);
String dishName = menu.getDish(i).getName();
String dishPrice = dollarValue.format(menu.getDish(i).getPrice());
- ui.showToUser(indexNum + ". " + dishName + " $" + dishPrice);
+ //ui.showToUser(indexNum + ". " + dishName + " $" + dishPrice);
+ ui.showToUserFormat(indexNum + ". " + dishName," $" + dishPrice);
}
+ ui.showToUser(UserOutput.MENU_TOP.message);
};
}
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 9f2dd89829..694d841da7 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -94,6 +94,17 @@ public void showToUser(String... message) {
}
}
+ /**
+ * Shows menu to user is table format
+ * @param dishName
+ * @param dishPrice
+ */
+ public void showToUserFormat(String dishName, String dishPrice) {
+ String leftAlignFormat = "| %-24s | %-12s |%n";
+ System.out.format(leftAlignFormat, dishName, dishPrice);
+ }
+ //+-----------------+------+
+
/**
* show edit price message to user
* @param menuItem menuItem that has been modified
diff --git a/src/main/java/seedu/cafectrl/ui/UserOutput.java b/src/main/java/seedu/cafectrl/ui/UserOutput.java
index 682d1231f6..bce33853c0 100644
--- a/src/main/java/seedu/cafectrl/ui/UserOutput.java
+++ b/src/main/java/seedu/cafectrl/ui/UserOutput.java
@@ -7,6 +7,10 @@ public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
LIST_MESSAGE("Ah, behold, the grand menu of delights!"),
+ MENU_TOP("+-----------------------------------------+"),
+ MENU_CORNER("+--------------------------+--------------+"),
+ MENU_TITLE("| Dish Name | Price |"),
+ LIST_MESSAGE_MENU("| Ah, behold, the grand menu of delights! |"),
ADD_DISH_MESSAGE("You have added the following dish..."),
UNKNOWN_COMMAND_MESSAGE("Your command has left me scratching my virtual head. Let's try that again, shall we?");
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index c8f538be52..0676df8d72 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -32,9 +32,9 @@ public void showToUser(String... message) {
String actualOutput = String.join(", ", commandOutput);
- String expectedOutput = "Ah, behold, the grand menu of delights!" +
- " 1. Chicken Rice $2.50" +
- " 2. Chicken Curry $4.30";
+ String expectedOutput = "Ah, behold, the grand menu of delights!"
+ + " 1. Chicken Rice $2.50"
+ + " 2. Chicken Curry $4.30";
assertEquals(expectedOutput.trim().replaceAll(", ", " "),
actualOutput.trim().replaceAll(", ", " "));
@@ -45,6 +45,6 @@ private static String convertArrayToString(String[] message, String delimiter) {
for (String str : message) {
sb.append(str.toString()).append(delimiter);
}
- return sb.substring(0, sb.length() -1);
+ return sb.substring(0, sb.length() - 1);
}
}
From c694c066583b13ef900278baa32b1df645b43fd6 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 23:16:55 +0800
Subject: [PATCH 145/870] Edit add dish parsing code to prevent negative price
input
---
src/main/java/seedu/cafectrl/parser/Parser.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index ea3a7102ff..4394f4c48c 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -144,6 +144,11 @@ private static Command prepareAdd(String arguments) {
float price = Float.parseFloat(matcher.group(PRICE_MATCHER_GROUP_NUM));
String ingredientsListString = matcher.group(INGREDIENT_LIST_MATCHER_GROUP_NUM);
+ IncorrectCommand MESSAGE_USAGE = checkNegativePrice(price);
+ if (MESSAGE_USAGE != null) {
+ return MESSAGE_USAGE;
+ }
+
// Capture the list of ingredients
ArrayList ingredients = new ArrayList<>();
@@ -161,6 +166,14 @@ private static Command prepareAdd(String arguments) {
}
}
+ private static IncorrectCommand checkNegativePrice(float price) {
+ if (price < 0) {
+ return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT"
+ + AddDishCommand.MESSAGE_USAGE);
+ }
+ return null;
+ }
+
private static IncorrectCommand ingredientParsing(String ingredientsListString, ArrayList ingredients) {
String[] ingredientListInputText = {ingredientsListString};
From d1fa8a2f18fd567e65f8e22359f333e35cda5099 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Wed, 18 Oct 2023 23:19:29 +0800
Subject: [PATCH 146/870] Edit code to solve checkstyle issues
---
src/main/java/seedu/cafectrl/parser/Parser.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 4394f4c48c..ce2e33509e 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -144,17 +144,17 @@ private static Command prepareAdd(String arguments) {
float price = Float.parseFloat(matcher.group(PRICE_MATCHER_GROUP_NUM));
String ingredientsListString = matcher.group(INGREDIENT_LIST_MATCHER_GROUP_NUM);
- IncorrectCommand MESSAGE_USAGE = checkNegativePrice(price);
- if (MESSAGE_USAGE != null) {
- return MESSAGE_USAGE;
+ IncorrectCommand incorrectCommand1 = checkNegativePrice(price);
+ if (incorrectCommand1 != null) {
+ return incorrectCommand1;
}
// Capture the list of ingredients
ArrayList ingredients = new ArrayList<>();
- IncorrectCommand incorrectCommand = ingredientParsing(ingredientsListString, ingredients);
- if (incorrectCommand != null) {
- return incorrectCommand;
+ IncorrectCommand incorrectCommand2 = ingredientParsing(ingredientsListString, ingredients);
+ if (incorrectCommand2 != null) {
+ return incorrectCommand2;
}
Dish dish = new Dish(dishName, ingredients, price);
From b18deabd054b19780e3d5cc6eac3fe1e541643d1 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Thu, 19 Oct 2023 01:35:52 +0800
Subject: [PATCH 147/870] Update code to comply Gradle
---
src/main/java/seedu/cafectrl/command/ListMenuCommand.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index 8f7df7ea4f..02615a6f58 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -22,7 +22,8 @@ public class ListMenuCommand extends Command {
*/
@Override
public void execute(Menu menu, Ui ui) {
- ui.showToUser(UserOutput.MENU_TOP.message, UserOutput.LIST_MESSAGE_MENU.message, UserOutput.MENU_CORNER.message, UserOutput.MENU_TITLE.message, UserOutput.MENU_CORNER.message);
+ ui.showToUser(UserOutput.MENU_TOP.message, UserOutput.LIST_MESSAGE_MENU.message,
+ UserOutput.MENU_CORNER.message, UserOutput.MENU_TITLE.message, UserOutput.MENU_CORNER.message);
for(int i =0; i < menu.getSize(); i++) {
String indexNum = String.valueOf(i+1);
String dishName = menu.getDish(i).getName();
From 8e589d37d341acdb4abcb34da25475bdc8a04e33 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 11:22:33 +0800
Subject: [PATCH 148/870] Move all messages in to Message class
---
.../cafectrl/command/ListMenuCommand.java | 4 ++--
.../java/seedu/cafectrl/parser/Parser.java | 3 +--
src/main/java/seedu/cafectrl/ui/Messages.java | 18 ++++++++++++++++--
src/main/java/seedu/cafectrl/ui/Ui.java | 6 +++---
.../java/seedu/cafectrl/ui/UserOutput.java | 17 -----------------
.../java/seedu/cafectrl/parser/ParserTest.java | 3 +--
6 files changed, 23 insertions(+), 28 deletions(-)
delete mode 100644 src/main/java/seedu/cafectrl/ui/UserOutput.java
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index cf72fd8a53..d5c3354eb1 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -1,8 +1,8 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
-import seedu.cafectrl.ui.UserOutput;
import java.text.DecimalFormat;
@@ -22,7 +22,7 @@ public class ListMenuCommand extends Command {
*/
@Override
public void execute(Menu menu, Ui ui) {
- ui.showToUser(UserOutput.LIST_MESSAGE.message);
+ ui.showToUser(Messages.LIST_MESSAGE);
for(int i =0; i < menu.getSize(); i++) {
String indexNum = String.valueOf(i+1);
String dishName = menu.getDish(i).getName();
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 0b690baca8..a4fd7b8f98 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -13,7 +13,6 @@
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
-import seedu.cafectrl.ui.UserOutput;
import java.util.ArrayList;
import java.util.regex.Matcher;
@@ -84,7 +83,7 @@ public static Command parseCommand(Menu menu, String userInput) {
return new ExitCommand();
default:
- return new IncorrectCommand(UserOutput.UNKNOWN_COMMAND_MESSAGE.message);
+ return new IncorrectCommand(Messages.UNKNOWN_COMMAND_MESSAGE);
}
}
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index d8d36ce5c3..140b548824 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -6,6 +6,9 @@ public class Messages {
public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments "
+ "for edit price command.";
+ public static final String MISSING_ARGUMENT_FOR_LIST_INGREDIENTS = "Error: Missing arguments "
+ + "for list ingredients command.";
+
public static final String MISSING_ARGUMENT_FOR_DELETE = "Error: Missing arguments "
+ "for delete command.";
@@ -14,9 +17,20 @@ public class Messages {
+ "Make sure dish index is "
+ "of type int and price is of type float!";
+ public static final String UNKNOWN_COMMAND_MESSAGE = "Error: Your command has left me scratching my virtual head. "
+ + "Let's try that again, shall we?";
+
// Ui messages
public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
- public static final String MISSING_ARGUMENT_FOR_LIST_INGREDIENTS = "Error: Missing arguments "
- + "for list ingredients command.";
+ public static final String WELCOME_MESSAGE = "Hello! Welcome to CafeCTRL!";
+
+ public static final String GOODBYE_MESSAGE = "Goodbye <3 Have a great day ahead!";
+
+ public static final String LIST_MESSAGE = "Ah, behold, the grand menu of delights!";
+
+ public static final String ADD_DISH_MESSAGE = "You have added the following dish...";
+
+
+
}
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 809a75658f..300288e86e 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -28,11 +28,11 @@ public String receiveUserInput() {
}
public void showWelcome() {
- showToUser(UserOutput.WELCOME_MESSAGE.message);
+ showToUser(Messages.WELCOME_MESSAGE);
}
public void showGoodbye() {
- showToUser(UserOutput.GOODBYE_MESSAGE.message);
+ showToUser(Messages.GOODBYE_MESSAGE);
}
/**
@@ -68,7 +68,7 @@ public void printAddDishMessage(Dish dish) {
.append("\n");
}
- showToUser(UserOutput.ADD_DISH_MESSAGE.message,
+ showToUser(Messages.ADD_DISH_MESSAGE,
dishNameString,
dishPriceString,
dishIngredientsString.toString());
diff --git a/src/main/java/seedu/cafectrl/ui/UserOutput.java b/src/main/java/seedu/cafectrl/ui/UserOutput.java
deleted file mode 100644
index 682d1231f6..0000000000
--- a/src/main/java/seedu/cafectrl/ui/UserOutput.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package seedu.cafectrl.ui;
-
-/**
- * Enumerates messages to be displayed to users.
- */
-public enum UserOutput {
- WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
- GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
- LIST_MESSAGE("Ah, behold, the grand menu of delights!"),
- ADD_DISH_MESSAGE("You have added the following dish..."),
- UNKNOWN_COMMAND_MESSAGE("Your command has left me scratching my virtual head. Let's try that again, shall we?");
-
- public final String message;
- UserOutput(String message) {
- this.message = message;
- }
-}
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index e1bbde9042..19414ae50f 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -11,7 +11,6 @@
import seedu.cafectrl.data.dish.Ingredient;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
-import seedu.cafectrl.ui.UserOutput;
import java.util.ArrayList;
import java.util.Arrays;
@@ -161,7 +160,7 @@ public void showToUser(String... message) {
Command commandReturned = Parser.parseCommand(menu, testUserInput);
commandReturned.execute(menu, ui);
- assertEquals(UserOutput.UNKNOWN_COMMAND_MESSAGE.message, actualOutput.get(0));
+ assertEquals(Messages.UNKNOWN_COMMAND_MESSAGE, actualOutput.get(0));
}
@Test
From 12bc39306efa8ba725bcbe10c93079d745569e03 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 12:11:06 +0800
Subject: [PATCH 149/870] Update unknown command message
Fixes #78
---
src/main/java/seedu/cafectrl/ui/Messages.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 140b548824..1b1e46d743 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -17,8 +17,8 @@ public class Messages {
+ "Make sure dish index is "
+ "of type int and price is of type float!";
- public static final String UNKNOWN_COMMAND_MESSAGE = "Error: Your command has left me scratching my virtual head. "
- + "Let's try that again, shall we?";
+ public static final String UNKNOWN_COMMAND_MESSAGE = "Error: Unknown command. "
+ + "Type 'help' to view the accepted list of commands";
// Ui messages
public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
From b1aac1c4b0473c620dcb918ceb878ab12757384a Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Sun, 22 Oct 2023 14:01:35 +0800
Subject: [PATCH 150/870] Add method for empty menu
---
.../seedu/cafectrl/command/ListMenuCommand.java | 15 +++++++++++++--
src/main/java/seedu/cafectrl/ui/UserOutput.java | 1 +
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index 02615a6f58..09b5769979 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -22,15 +22,26 @@ public class ListMenuCommand extends Command {
*/
@Override
public void execute(Menu menu, Ui ui) {
+ if (menu.getSize() == 0) {
+ printEmptyMenu(ui);
+ return;
+ }
+ printFullMenu(menu, ui);
+ };
+
+ public void printEmptyMenu(Ui ui) {
+ ui.showToUser(UserOutput.MENU_EMPTY.message);
+ }
+
+ public void printFullMenu(Menu menu, Ui ui) {
ui.showToUser(UserOutput.MENU_TOP.message, UserOutput.LIST_MESSAGE_MENU.message,
UserOutput.MENU_CORNER.message, UserOutput.MENU_TITLE.message, UserOutput.MENU_CORNER.message);
for(int i =0; i < menu.getSize(); i++) {
String indexNum = String.valueOf(i+1);
String dishName = menu.getDish(i).getName();
String dishPrice = dollarValue.format(menu.getDish(i).getPrice());
- //ui.showToUser(indexNum + ". " + dishName + " $" + dishPrice);
ui.showToUserFormat(indexNum + ". " + dishName," $" + dishPrice);
}
ui.showToUser(UserOutput.MENU_TOP.message);
- };
+ }
}
diff --git a/src/main/java/seedu/cafectrl/ui/UserOutput.java b/src/main/java/seedu/cafectrl/ui/UserOutput.java
index bce33853c0..bab0b67bfe 100644
--- a/src/main/java/seedu/cafectrl/ui/UserOutput.java
+++ b/src/main/java/seedu/cafectrl/ui/UserOutput.java
@@ -7,6 +7,7 @@ public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
LIST_MESSAGE("Ah, behold, the grand menu of delights!"),
+ MENU_EMPTY("It seems our menu is currently taking a break. Let's give it a wake-up call and fill 'er up with delectable delights, shall we?"),
MENU_TOP("+-----------------------------------------+"),
MENU_CORNER("+--------------------------+--------------+"),
MENU_TITLE("| Dish Name | Price |"),
From 69168a3d641267d405a4019bcbade582689e8d5f Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Sun, 22 Oct 2023 14:04:18 +0800
Subject: [PATCH 151/870] Update code to comply with Gradle
---
src/main/java/seedu/cafectrl/ui/UserOutput.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/ui/UserOutput.java b/src/main/java/seedu/cafectrl/ui/UserOutput.java
index bab0b67bfe..6636072bf0 100644
--- a/src/main/java/seedu/cafectrl/ui/UserOutput.java
+++ b/src/main/java/seedu/cafectrl/ui/UserOutput.java
@@ -7,7 +7,8 @@ public enum UserOutput {
WELCOME_MESSAGE("Hello! Welcome to CafeCTRL!"),
GOODBYE_MESSAGE("Goodbye <3 Have a great day ahead!"),
LIST_MESSAGE("Ah, behold, the grand menu of delights!"),
- MENU_EMPTY("It seems our menu is currently taking a break. Let's give it a wake-up call and fill 'er up with delectable delights, shall we?"),
+ MENU_EMPTY("It seems our menu is currently taking a break. "
+ + "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?"),
MENU_TOP("+-----------------------------------------+"),
MENU_CORNER("+--------------------------+--------------+"),
MENU_TITLE("| Dish Name | Price |"),
From 927b64d77278cb15a7b0f986d7719a29bb655771 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Sun, 22 Oct 2023 14:41:29 +0800
Subject: [PATCH 152/870] Update JUnit for ListMenu
---
.../cafectrl/command/ListMenuCommandTest.java | 26 +++++++++++++------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index 0676df8d72..ff471aa912 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -25,19 +25,29 @@ public void showToUser(String... message) {
String parseString = convertArrayToString(message, ",");
commandOutput.add(parseString);
}
+ @Override
+ public void showToUserFormat(String dishName, String dishPrice) {
+ String leftAlignFormat = "| %-24s | %-12s |";
+ String parseString = String.format(leftAlignFormat, dishName, dishPrice);
+ commandOutput.add(parseString);
+ }
};
Command listMenuCommand = new ListMenuCommand();
listMenuCommand.execute(menu, ui);
- String actualOutput = String.join(", ", commandOutput);
-
- String expectedOutput = "Ah, behold, the grand menu of delights!"
- + " 1. Chicken Rice $2.50"
- + " 2. Chicken Curry $4.30";
-
- assertEquals(expectedOutput.trim().replaceAll(", ", " "),
- actualOutput.trim().replaceAll(", ", " "));
+ String actualOutput = String.join(",", commandOutput);
+
+ String expectedOutput = "+-----------------------------------------+"
+ + "| Ah, behold, the grand menu of delights! |"
+ + "+--------------------------+--------------+"
+ + "| Dish Name | Price |"
+ + "+--------------------------+--------------+"
+ + "| 1. Chicken Rice | $2.50 |"
+ + "| 2. Chicken Curry | $4.30 |"
+ + "+-----------------------------------------+";
+
+ assert (expectedOutput.trim().replaceAll(",", "").equals(actualOutput.trim().replaceAll(",", "")));
}
private static String convertArrayToString(String[] message, String delimiter) {
From 65510e0cc0896dd9dbb314673257289143d76e40 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Sun, 22 Oct 2023 15:29:04 +0800
Subject: [PATCH 153/870] Update ListMenu to use Messages.java
---
src/main/java/seedu/cafectrl/ui/Messages.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 1b1e46d743..7122b36dd2 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -27,7 +27,12 @@ public class Messages {
public static final String GOODBYE_MESSAGE = "Goodbye <3 Have a great day ahead!";
- public static final String LIST_MESSAGE = "Ah, behold, the grand menu of delights!";
+ public static final String LIST_MENU_MESSAGE = "| Ah, behold, the grand menu of delights! |";
+ public static final String MENU_EMPTY_MESSAGE = "It seems our menu is currently taking a break. "
+ + "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?";
+ public static final String MENU_TOP = "+-----------------------------------------+";
+ public static final String MENU_CORNER = "+--------------------------+--------------+";
+ public static final String MENU_TITLE = "| Dish Name | Price |";
public static final String ADD_DISH_MESSAGE = "You have added the following dish...";
From 82d0bd4a04fc3ed9706de6e21369c75a97131511 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 15:38:09 +0800
Subject: [PATCH 154/870] Implement view total stock in pantry feature
---
.../command/ViewTotalStockCommand.java | 26 +++++++++++++++++++
.../java/seedu/cafectrl/parser/Parser.java | 9 +++++++
2 files changed, 35 insertions(+)
create mode 100644 src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
diff --git a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
new file mode 100644
index 0000000000..d5b5e878fe
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
@@ -0,0 +1,26 @@
+package seedu.cafectrl.command;
+
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
+import seedu.cafectrl.data.dish.Ingredient;
+import seedu.cafectrl.ui.Ui;
+
+import java.util.ArrayList;
+
+public class ViewTotalStockCommand extends Command {
+
+ private ArrayList pantryStock;
+ public static final String COMMAND_WORD = "view_stock";
+
+ private Pantry pantry;
+
+ @Override
+ public void execute(Menu menu, Ui ui) {
+ pantryStock = pantry.getPantryStock();
+
+ for (Ingredient ingredient : pantryStock) {
+ ui.showToUser(ingredient.getName() + " " + ingredient.getQuantity());
+ }
+ }
+}
+
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 0b690baca8..a9b1aab14f 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -8,6 +8,7 @@
import seedu.cafectrl.command.ExitCommand;
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.command.ListMenuCommand;
+import seedu.cafectrl.command.ViewTotalStockCommand;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.data.Menu;
@@ -80,6 +81,9 @@ public static Command parseCommand(Menu menu, String userInput) {
case EditPriceCommand.COMMAND_WORD:
return prepareEditPriceCommand(menu, arguments);
+ case ViewTotalStockCommand.COMMAND_WORD:
+ return prepareViewTotalStock();
+
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
@@ -88,6 +92,7 @@ public static Command parseCommand(Menu menu, String userInput) {
}
}
+
// All prepareCommand Classes
private static Command prepareListMenu() {
return new ListMenuCommand();
@@ -252,6 +257,10 @@ private static Command prepareDelete(Menu menu, String arguments) {
return new DeleteDishCommand(dishIndex);
}
+ private static Command prepareViewTotalStock() {
+ return new ViewTotalStockCommand();
+ }
+
/**
* Parses the given arguments string to identify task index number.
*
From 793446992cc666d6865910f66025374082ad37d9 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 22 Oct 2023 17:03:51 +0800
Subject: [PATCH 155/870] Ui.java: rename showToUerFormat to formatListMenu
---
src/main/java/seedu/cafectrl/command/ListMenuCommand.java | 2 +-
src/main/java/seedu/cafectrl/ui/Ui.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index c8faaed8a7..22c2d5f657 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -40,7 +40,7 @@ public void printFullMenu(Menu menu, Ui ui) {
String indexNum = String.valueOf(i+1);
String dishName = menu.getDish(i).getName();
String dishPrice = dollarValue.format(menu.getDish(i).getPrice());
- ui.showToUserFormat(indexNum + ". " + dishName," $" + dishPrice);
+ ui.formatListMenu(indexNum + ". " + dishName," $" + dishPrice);
}
ui.showToUser(Messages.MENU_TOP);
}
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index ba2c22ba35..c8ddda1d7c 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -99,7 +99,7 @@ public void showToUser(String... message) {
* @param dishName
* @param dishPrice
*/
- public void showToUserFormat(String dishName, String dishPrice) {
+ public void formatListMenu(String dishName, String dishPrice) {
String leftAlignFormat = "| %-24s | %-12s |%n";
System.out.format(leftAlignFormat, dishName, dishPrice);
}
From cec3c524bbd1d3ef76e0e833435fef721827d145 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 22 Oct 2023 17:12:08 +0800
Subject: [PATCH 156/870] Implement help command
fixes #73
---
.../seedu/cafectrl/command/HelpCommand.java | 14 +++++
.../java/seedu/cafectrl/parser/Parser.java | 19 +++---
src/main/java/seedu/cafectrl/ui/Messages.java | 63 ++++++++++++-------
src/main/java/seedu/cafectrl/ui/Ui.java | 5 ++
.../cafectrl/command/ListMenuCommandTest.java | 2 +-
5 files changed, 71 insertions(+), 32 deletions(-)
create mode 100644 src/main/java/seedu/cafectrl/command/HelpCommand.java
diff --git a/src/main/java/seedu/cafectrl/command/HelpCommand.java b/src/main/java/seedu/cafectrl/command/HelpCommand.java
new file mode 100644
index 0000000000..9f4b4e5532
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/command/HelpCommand.java
@@ -0,0 +1,14 @@
+package seedu.cafectrl.command;
+
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Ui;
+
+public class HelpCommand extends Command {
+ public static final String COMMAND_WORD = "help";
+
+ @Override
+ public void execute(Menu menu, Ui ui) {
+ ui.printLine();
+ ui.showHelp();
+ }
+}
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index a4fd7b8f98..dcc358b411 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -2,13 +2,13 @@
import seedu.cafectrl.command.AddDishCommand;
import seedu.cafectrl.command.Command;
-import seedu.cafectrl.command.IncorrectCommand;
import seedu.cafectrl.command.DeleteDishCommand;
import seedu.cafectrl.command.EditPriceCommand;
import seedu.cafectrl.command.ExitCommand;
+import seedu.cafectrl.command.HelpCommand;
+import seedu.cafectrl.command.IncorrectCommand;
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.command.ListMenuCommand;
-
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.dish.Dish;
@@ -79,6 +79,9 @@ public static Command parseCommand(Menu menu, String userInput) {
case EditPriceCommand.COMMAND_WORD:
return prepareEditPriceCommand(menu, arguments);
+ case HelpCommand.COMMAND_WORD:
+ return prepareHelpCommand();
+
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
@@ -87,15 +90,13 @@ public static Command parseCommand(Menu menu, String userInput) {
}
}
- // All prepareCommand Classes
+ /**
+ * All prepareCommand Classes
+ */
private static Command prepareListMenu() {
return new ListMenuCommand();
}
- private static Command prepareEditListCommand(String arguments) {
- return null;
- }
-
/**
* Parse argument in the context of edit price command
* @param menu menu of the current session
@@ -251,6 +252,10 @@ private static Command prepareDelete(Menu menu, String arguments) {
return new DeleteDishCommand(dishIndex);
}
+ private static Command prepareHelpCommand() {
+ return new HelpCommand();
+ }
+
/**
* Parses the given arguments string to identify task index number.
*
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 7122b36dd2..c2999093e3 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -1,32 +1,21 @@
package seedu.cafectrl.ui;
public class Messages {
-
- // Error messages
- public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments "
- + "for edit price command.";
-
- public static final String MISSING_ARGUMENT_FOR_LIST_INGREDIENTS = "Error: Missing arguments "
- + "for list ingredients command.";
-
- public static final String MISSING_ARGUMENT_FOR_DELETE = "Error: Missing arguments "
- + "for delete command.";
-
- public static final String INVALID_DISH_INDEX = "Error: Invalid dish index.";
- public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Error: Invalid dish index. \n "
- + "Make sure dish index is "
- + "of type int and price is of type float!";
-
- public static final String UNKNOWN_COMMAND_MESSAGE = "Error: Unknown command. "
- + "Type 'help' to view the accepted list of commands";
-
- // Ui messages
- public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
-
+ /**
+ * Greeting messages
+ */
public static final String WELCOME_MESSAGE = "Hello! Welcome to CafeCTRL!";
public static final String GOODBYE_MESSAGE = "Goodbye <3 Have a great day ahead!";
+ /**
+ * Messages for edit price command
+ */
+ public static final String PRICE_MODIFIED_MESSAGE = "Price modified for the following dish: ";
+
+ /**
+ * Messages for list menu command
+ */
public static final String LIST_MENU_MESSAGE = "| Ah, behold, the grand menu of delights! |";
public static final String MENU_EMPTY_MESSAGE = "It seems our menu is currently taking a break. "
+ "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?";
@@ -34,8 +23,34 @@ public class Messages {
public static final String MENU_CORNER = "+--------------------------+--------------+";
public static final String MENU_TITLE = "| Dish Name | Price |";
+ /**
+ * Messages for add dish command
+ */
public static final String ADD_DISH_MESSAGE = "You have added the following dish...";
-
-
+ /**
+ * Messages for help command
+ */
+ public static final String LIST_OF_COMMANDS = "These are all the commands I recognise: ";
+ public static final String ADD_DISH_GUIDE = "";
+ public static final String LIST_MENU_GUIDE = "";
+ public static final String LIST_INGREDIENTS_GUIDE = "";
+ public static final String DELETE_GUIDE = "";
+ public static final String EDIT_PRICE_GUIDE = "";
+
+ /**
+ * Error messages
+ */
+ public static final String MISSING_ARGUMENT_FOR_EDIT_PRICE = "Error: Missing arguments "
+ + "for edit price command.";
+ public static final String MISSING_ARGUMENT_FOR_LIST_INGREDIENTS = "Error: Missing arguments "
+ + "for list ingredients command.";
+ public static final String MISSING_ARGUMENT_FOR_DELETE = "Error: Missing arguments "
+ + "for delete command.";
+ public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Error: Invalid dish index. \n "
+ + "Make sure dish index is "
+ + "of type int and price is of type float!";
+ public static final String UNKNOWN_COMMAND_MESSAGE = "Error: Unknown command. "
+ + "Type 'help' to view the accepted list of commands";
+ public static final String INVALID_DISH_INDEX = "Error: Invalid dish index.";
}
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index c8ddda1d7c..4ee986b27a 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -112,4 +112,9 @@ public void formatListMenu(String dishName, String dishPrice) {
public void showEditPriceMessage(String menuItem) {
this.showToUser(Messages.PRICE_MODIFIED_MESSAGE, menuItem);
}
+
+ public void showHelp() {
+ showToUser(Messages.LIST_OF_COMMANDS, Messages.ADD_DISH_GUIDE, Messages.LIST_MENU_GUIDE,
+ Messages.LIST_INGREDIENTS_GUIDE, Messages.DELETE_GUIDE, Messages.EDIT_PRICE_GUIDE);
+ }
}
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index ff471aa912..7c3d228744 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -26,7 +26,7 @@ public void showToUser(String... message) {
commandOutput.add(parseString);
}
@Override
- public void showToUserFormat(String dishName, String dishPrice) {
+ public void formatListMenu(String dishName, String dishPrice) {
String leftAlignFormat = "| %-24s | %-12s |";
String parseString = String.format(leftAlignFormat, dishName, dishPrice);
commandOutput.add(parseString);
From cfe46d6d3284681a80fa99ef46fbc4f4c0c2963c Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 22 Oct 2023 17:32:53 +0800
Subject: [PATCH 157/870] Complete messages for help command
---
src/main/java/seedu/cafectrl/ui/Messages.java | 23 +++++++++++++++----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index c2999093e3..729e37a484 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -32,11 +32,24 @@ public class Messages {
* Messages for help command
*/
public static final String LIST_OF_COMMANDS = "These are all the commands I recognise: ";
- public static final String ADD_DISH_GUIDE = "";
- public static final String LIST_MENU_GUIDE = "";
- public static final String LIST_INGREDIENTS_GUIDE = "";
- public static final String DELETE_GUIDE = "";
- public static final String EDIT_PRICE_GUIDE = "";
+ public static final String INSTRUCTION_ON_COMMAND_FORMAT = "(- Words in UPPER_CASE are "
+ + "the parameters to be supplied by the user.\n"
+ + "e.g. in add name/NAME, NAME is a parameter that can be used as add name/Chicken.\n"
+ + "- Parameters in [] are optional.)";
+ public static final String ADD_DISH_GUIDE = "To add a new dish to the menu: "
+ + "add name/NAME price/PRICE ingredient/INGREDIENT1_NAME qty/INGREDIENT1_QTY"
+ + "[, ingredient/INGREDIENT2_NAME qty/INGREDIENT2_QTY\n"
+ + "Example: add name/chicken rice price/3 ingredient/rice qty/100, ingredient/chicken qty/100";
+ public static final String LIST_MENU_GUIDE = "To list out all dishes on the menu: list_menu";
+ public static final String LIST_INGREDIENTS_GUIDE = "To list out the ingredients needed "
+ + "for a specific dish: list_ingredients DISH_INDEX\n"
+ + "Example: list_ingredients 1";
+ public static final String DELETE_GUIDE = "To delete a menu item "
+ + "delete DISH_INDEX\n"
+ + "Example: delete 1";
+ public static final String EDIT_PRICE_GUIDE = "To edit price of a menu item: "
+ + "edit_price index/DISH_INDEX price/NEW_PRICE\n"
+ + "Example: edit_price index/1 price/4.50";
/**
* Error messages
From 494813d67cce020f13b6bf14eaa9268b838fbbde Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 22 Oct 2023 17:33:42 +0800
Subject: [PATCH 158/870] Ui.java: add method showToUserWithSpaceBetweenLines
for showHelp()
---
src/main/java/seedu/cafectrl/ui/Ui.java | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 4ee986b27a..3eb4e92bbf 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -114,7 +114,14 @@ public void showEditPriceMessage(String menuItem) {
}
public void showHelp() {
- showToUser(Messages.LIST_OF_COMMANDS, Messages.ADD_DISH_GUIDE, Messages.LIST_MENU_GUIDE,
- Messages.LIST_INGREDIENTS_GUIDE, Messages.DELETE_GUIDE, Messages.EDIT_PRICE_GUIDE);
+ showToUserWithSpaceBetweenLines(Messages.LIST_OF_COMMANDS, Messages.INSTRUCTION_ON_COMMAND_FORMAT,
+ Messages.ADD_DISH_GUIDE, Messages.LIST_MENU_GUIDE, Messages.LIST_INGREDIENTS_GUIDE,
+ Messages.DELETE_GUIDE, Messages.EDIT_PRICE_GUIDE);
+ }
+
+ private void showToUserWithSpaceBetweenLines(String... message) {
+ for (String m: message) {
+ System.out.println(m + "\n");
+ }
}
}
From 56fbe7c76d7c928a696fb1a31922f88a13947a25 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 22 Oct 2023 17:46:01 +0800
Subject: [PATCH 159/870] Add JUnit test for HelpCommand (incomplete)
---
src/main/java/seedu/cafectrl/ui/Ui.java | 2 +-
.../cafectrl/command/HelpCommandTest.java | 37 +++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
create mode 100644 src/test/java/seedu/cafectrl/command/HelpCommandTest.java
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 3eb4e92bbf..005742131d 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -119,7 +119,7 @@ public void showHelp() {
Messages.DELETE_GUIDE, Messages.EDIT_PRICE_GUIDE);
}
- private void showToUserWithSpaceBetweenLines(String... message) {
+ public void showToUserWithSpaceBetweenLines(String... message) {
for (String m: message) {
System.out.println(m + "\n");
}
diff --git a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
new file mode 100644
index 0000000000..e7fc7a98e1
--- /dev/null
+++ b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
@@ -0,0 +1,37 @@
+package seedu.cafectrl.command;
+
+import org.junit.jupiter.api.Test;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Messages;
+import seedu.cafectrl.command.HelpCommand;
+import seedu.cafectrl.ui.Ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class HelpCommandTest {
+
+ @Test
+ void execute_validInput_editPrice() {
+
+ ArrayList actualOutput = new ArrayList<>();
+ Menu menu = new Menu();
+ Ui ui = new Ui() {
+ @Override
+ public void showToUser(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+
+ @Override
+ public void showToUserWithSpaceBetweenLines(String... message) {
+ actualOutput.addAll(Arrays.asList(message));
+ }
+ };
+
+ HelpCommand helpCommand = new HelpCommand();
+ helpCommand.execute(menu, ui);
+ }
+
+}
\ No newline at end of file
From b6f15b18161b307a88ec6e2cb43f496e908bfcba Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Sun, 22 Oct 2023 17:48:24 +0800
Subject: [PATCH 160/870] HelpCommandtest.java: improve code quality
---
src/test/java/seedu/cafectrl/command/HelpCommandTest.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
index e7fc7a98e1..9613297d89 100644
--- a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
@@ -2,14 +2,12 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
-import seedu.cafectrl.ui.Messages;
-import seedu.cafectrl.command.HelpCommand;
import seedu.cafectrl.ui.Ui;
import java.util.ArrayList;
import java.util.Arrays;
-import static org.junit.jupiter.api.Assertions.*;
+//import static org.junit.jupiter.api.Assertions.assertEquals;
class HelpCommandTest {
@@ -34,4 +32,4 @@ public void showToUserWithSpaceBetweenLines(String... message) {
helpCommand.execute(menu, ui);
}
-}
\ No newline at end of file
+}
From 851cba3e9f44f4e438b57a904820b0cf3cd7c870 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 21:39:39 +0800
Subject: [PATCH 161/870] Implement Pantry class
---
src/main/java/seedu/cafectrl/data/Pantry.java | 119 ++++++++++++++++++
1 file changed, 119 insertions(+)
create mode 100644 src/main/java/seedu/cafectrl/data/Pantry.java
diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java
new file mode 100644
index 0000000000..d0091d9f99
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/data/Pantry.java
@@ -0,0 +1,119 @@
+package seedu.cafectrl.data;
+
+import seedu.cafectrl.data.dish.Ingredient;
+
+import java.util.ArrayList;
+
+/**
+ * Represents a pantry that stores ingredients and manages their quantities.
+ */
+public class Pantry {
+
+ private ArrayList pantryStock;
+
+ /**
+ * Retrieves the current pantry stock from storage, which may include reading from a file (pantry.txt).
+ * @return An ArrayList of Ingredient objects representing the current pantry stock.
+ */
+ public ArrayList getPantryStock() {
+ pantryStock.addAll(retrieveStockFromStorage());
+ return pantryStock;
+ }
+
+ /**
+ * Retrieves the pantry stock from storage, e.g., by reading from a file (pantry.txt).
+ * @return An ArrayList of Ingredient objects representing the pantry stock.
+ */
+ public ArrayList retrieveStockFromStorage () {
+ ArrayList pantryStock = new ArrayList<>();
+ //TODO: Add file reader to read from pantry.txt
+ return pantryStock;
+ }
+
+ /**
+ * Extracts the quantity (numeric part) from a given string containing both quantity and unit.
+ * @param qty A string containing both quantity and unit (e.g., "100g").
+ * @return An integer representing the extracted quantity.
+ */
+ public int extractQty(String qty) {
+ return Integer.parseInt(qty.replaceAll("[^0-9]", ""));
+ }
+
+ /**
+ * Extracts the unit (non-numeric part) from a given string containing both quantity and unit.
+ * @param qty A string containing both quantity and unit (e.g., "100g").
+ * @return A string representing the extracted unit.
+ */
+ public String extractUnit(String qty) {
+ return qty.replaceAll("[0-9]", "");
+ }
+
+ /**
+ * Adds or updates an ingredient in the pantry stock based on its name and quantity.
+ * @param name The name of the ingredient to add or update.
+ * @param qty The quantity of the ingredient (e.g., "100g").
+ * @return The Ingredient object that was added or updated in the pantry stock.
+ */
+ public Ingredient addIngredientToStock (String name, String qty) {
+ pantryStock = getPantryStock(); //get latest pantry stock
+ int ingredientIndex = -1;
+
+ //checks if ingredient exists in the pantry
+ ingredientIndex = getIndexOfIngredient(name);
+
+ //TODO: Add file writer to write update pantry.txt
+ return updateIngredient(name, qty, ingredientIndex);
+ }
+
+ /**
+ * Updates an ingredient's quantity in the pantry stock or adds a new ingredient if it doesn't exist.
+ * @param name The name of the ingredient.
+ * @param qty The quantity of the ingredient (e.g., "100g").
+ * @param ingredientIndex The index of the ingredient in the pantry stock (-1 if not found).
+ * @return The Ingredient object that was added or updated in the pantry stock.
+ */
+ private Ingredient updateIngredient(String name, String qty, int ingredientIndex) {
+ Ingredient ingredient;
+ if (ingredientIndex != -1) { //ingredient is in pantry
+ ingredient = pantryStock.get(ingredientIndex);
+ qty = updateQty(ingredientIndex, qty);
+ ingredient.setQuantity(qty);
+ } else {
+ ingredient = new Ingredient(name, qty);
+ pantryStock.add(ingredient);
+ }
+ return ingredient;
+ }
+
+ /**
+ * Updates the quantity of an ingredient in the pantry stock.
+ * @param ingredientIndex The index of the ingredient in the pantry stock.
+ * @param qtyToAdd The quantity to add to the existing quantity (e.g., "100g").
+ * @return The updated quantity string (e.g., "200g").
+ */
+ private String updateQty(int ingredientIndex, String qtyToAdd) {
+ String unit = extractUnit(qtyToAdd); //remove numbers
+
+ String qtyToUpdate = pantryStock.get(ingredientIndex).getQuantity();
+
+ int intQtyToAdd = extractQty(qtyToAdd);
+ int intQtyToUpdate = extractQty(qtyToUpdate);
+
+ intQtyToUpdate += intQtyToAdd;
+ return intQtyToUpdate + unit;
+ }
+
+ /**
+ * Gets the index of an ingredient in the pantry stock based on its name (case-insensitive comparison).
+ * @param name The name of the ingredient to search for.
+ * @return The index of the ingredient in the pantry stock or -1 if not found.
+ */
+ private int getIndexOfIngredient(String name) {
+ for (int i = 0; i < pantryStock.size(); i++) {
+ if (name.equalsIgnoreCase(pantryStock.get(i).getName().trim())) {
+ return i;
+ }
+ }
+ return -1;
+ }
+}
From 8a23bd2fcd39cb9e460fd15fa31884e5e6513ad8 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 21:40:01 +0800
Subject: [PATCH 162/870] Add view total stock command
---
.../seedu/cafectrl/command/ViewTotalStockCommand.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
index d5b5e878fe..917c579c9c 100644
--- a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
@@ -3,19 +3,25 @@
import seedu.cafectrl.data.Menu;
import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Ingredient;
+import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
import java.util.ArrayList;
public class ViewTotalStockCommand extends Command {
- private ArrayList pantryStock;
public static final String COMMAND_WORD = "view_stock";
-
+ private ArrayList pantryStock;
private Pantry pantry;
+ public ViewTotalStockCommand() {
+ this.pantry = new Pantry();
+ }
+
@Override
public void execute(Menu menu, Ui ui) {
+
+ ui.showToUser(Messages.VIEW_STOCK);
pantryStock = pantry.getPantryStock();
for (Ingredient ingredient : pantryStock) {
From c421353e71a17d12dedffd0c40d9f3a0026b2522 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 21:40:25 +0800
Subject: [PATCH 163/870] Add buy ingredient command
---
.../command/BuyIngredientCommand.java | 29 +++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java
diff --git a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java
new file mode 100644
index 0000000000..a0fa314764
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java
@@ -0,0 +1,29 @@
+package seedu.cafectrl.command;
+
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
+import seedu.cafectrl.data.dish.Ingredient;
+import seedu.cafectrl.ui.Ui;
+
+public class BuyIngredientCommand extends Command {
+
+ //command format: buy_ingredient ingredient/[INGREDIENT_NAME] qty/[QUANTITY]
+ public static final String COMMAND_WORD = "buy_ingredient";
+
+ private String ingredientName;
+ private String ingredientQty;
+ private Pantry pantry;
+
+
+ public BuyIngredientCommand(String name, String qty) {
+ this.ingredientName = name;
+ this.ingredientQty = qty;
+ this.pantry = new Pantry();
+ }
+
+ @Override
+ public void execute(Menu menu, Ui ui) {
+ Ingredient ingredient = pantry.addIngredientToStock(ingredientName, ingredientQty);
+ ui.showBuyIngredientMessage(ingredient);
+ }
+}
From 19276cf1582acf1ef53f0733417a6af8a3422933 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 21:41:14 +0800
Subject: [PATCH 164/870] Add Ui support for viewTotalStock and buyIngredients
---
src/main/java/seedu/cafectrl/ui/Ui.java | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index ba2c22ba35..2672eb5a21 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -83,6 +83,13 @@ public void showDeleteMessage(Dish selectedDish) {
showToUser("Okay! " + selectedDish.getName() + " is deleted! :)");
}
+ public void showBuyIngredientMessage(Ingredient ingredient) {
+ String header = "Added to stock: \n";
+ String ingredientString = "Ingredient: " + ingredient.getName()
+ + " Qty: " + ingredient.getQuantity();
+ showToUser(header + ingredientString);
+ }
+
/**
* Shows messages(s) to the user
From a3094cde4ebc7ec9c301bf89bff04137ba67dd69 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 21:41:53 +0800
Subject: [PATCH 165/870] Add parser support for viewTotalStock and
buyIngredient
---
.../java/seedu/cafectrl/parser/Parser.java | 24 +++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 517740c94b..f9bd92989d 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -9,6 +9,7 @@
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.command.ListMenuCommand;
import seedu.cafectrl.command.ViewTotalStockCommand;
+import seedu.cafectrl.command.BuyIngredientCommand;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.data.Menu;
@@ -45,7 +46,6 @@ public class Parser {
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
-
/**
* Parse userInput and group it under commandWord and arguments
* use commandWord to find the matching command and prepare the command
@@ -83,6 +83,9 @@ public static Command parseCommand(Menu menu, String userInput) {
case ViewTotalStockCommand.COMMAND_WORD:
return prepareViewTotalStock();
+ case BuyIngredientCommand.COMMAND_WORD:
+ return prepareBuyIngredient(arguments);
+
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
@@ -91,7 +94,6 @@ public static Command parseCommand(Menu menu, String userInput) {
}
}
-
// All prepareCommand Classes
private static Command prepareListMenu() {
return new ListMenuCommand();
@@ -260,6 +262,24 @@ private static Command prepareViewTotalStock() {
return new ViewTotalStockCommand();
}
+ private static Command prepareBuyIngredient(String arguments) {
+ Pattern buyIngredientArgumentsPattern = Pattern.compile(INGREDIENT_ARGUMENT_STRING);
+ Matcher matcher = buyIngredientArgumentsPattern.matcher(arguments.trim());
+
+ if (!matcher.matches()) {
+ return new IncorrectCommand(Messages.MISSING_ARGUMENT_FOR_BUY_INGREDIENT);
+ }
+
+ String ingredientName = matcher.group(INGREDIENT_NAME_REGEX_GROUP_LABEL);
+ String ingredientQty = matcher.group(INGREDIENT_QTY_REGEX_GROUP_LABEL);
+
+ try {
+ return new BuyIngredientCommand(ingredientName, ingredientQty);
+ } catch (Exception e) {
+ return new IncorrectCommand(Messages.INVALID_ARGUMENT_FOR_BUY_INGREDIENT);
+ }
+ }
+
/**
* Parses the given arguments string to identify task index number.
*
From 9e878bd8f5dc5c24e8af6fba9b466b96b86af67b Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 21:42:18 +0800
Subject: [PATCH 166/870] Add setter for quantity varibale
---
src/main/java/seedu/cafectrl/data/dish/Ingredient.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
index 9fefb107eb..982f4767b2 100644
--- a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
+++ b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
@@ -2,7 +2,7 @@
public class Ingredient {
private final String name;
- private final String quantity;
+ private String quantity;
public Ingredient(String name) {
this.name = name;
@@ -22,6 +22,11 @@ public String getQuantity() {
return quantity;
}
+ public void setQuantity(String qty) {
+ this.quantity = qty;
+ }
+
+
@Override
public String toString() {
return name + " - " + quantity;
From 0b2987ab90909285001d2ae7dfbc04a414b527fc Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Sun, 22 Oct 2023 21:43:03 +0800
Subject: [PATCH 167/870] Add messages to display when error occurs
Fixes #90, Fixes #91
---
src/main/java/seedu/cafectrl/ui/Messages.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 7122b36dd2..b8e211ad85 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -12,6 +12,12 @@ public class Messages {
public static final String MISSING_ARGUMENT_FOR_DELETE = "Error: Missing arguments "
+ "for delete command.";
+ public static final String MISSING_ARGUMENT_FOR_BUY_INGREDIENT = "Error: Missing arguments "
+ + "for buy ingredient command.";
+
+ public static final String INVALID_ARGUMENT_FOR_BUY_INGREDIENT = "Error: Invalid arguments "
+ + "for buy ingredient command.";
+
public static final String INVALID_DISH_INDEX = "Error: Invalid dish index.";
public static final String WRONG_ARGUMENT_TYPE_FOR_EDIT_PRICE = "Error: Invalid dish index. \n "
+ "Make sure dish index is "
@@ -32,10 +38,10 @@ public class Messages {
+ "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?";
public static final String MENU_TOP = "+-----------------------------------------+";
public static final String MENU_CORNER = "+--------------------------+--------------+";
- public static final String MENU_TITLE = "| Dish Name | Price |";
+ public static final String MENU_TITLE = "| Dish Name | Price |";
public static final String ADD_DISH_MESSAGE = "You have added the following dish...";
-
+ public static final String VIEW_STOCK = "You have the following ingredients in pantry:";
}
From df0be27f0abb658365f85c686e483b4b7af8d9d9 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Sun, 22 Oct 2023 21:45:52 +0800
Subject: [PATCH 168/870] Implement stock checking of ingredients in Pantry
class
-Include decreasing of stock ingredients after processing each other
-Include checking of low stock ingredients
Fixes #92, Fixes #93
---
src/main/java/seedu/cafectrl/data/Pantry.java | 205 ++++++++++++++++++
.../seedu/cafectrl/data/dish/Ingredient.java | 6 +-
2 files changed, 210 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/seedu/cafectrl/data/Pantry.java
diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java
new file mode 100644
index 0000000000..d8a587725a
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/data/Pantry.java
@@ -0,0 +1,205 @@
+package seedu.cafectrl.data;
+
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.data.dish.Ingredient;
+import seedu.cafectrl.ui.Ui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class Pantry {
+
+ private ArrayList pantryStock;
+ private ArrayList menuItems;
+ private Ui ui;
+
+ public Pantry() {
+ this.ui = new Ui();
+ }
+
+ /**
+ * Checks the stock of ingredients and dish availability based on a given order.
+ */
+ public void checkIngredientsStock(){
+ //pass in dish when order function is completed
+ String dish = "Chicken Rice";
+ decreaseIngredientsStock(dish);
+ checkDishAvailability();
+ }
+
+ /**
+ * Decreases the stock of ingredients based on the given dish order.
+ *
+ * @param dish The name of the dish being ordered.
+ */
+ public void decreaseIngredientsStock(String dish){
+ ArrayList dishIngredients = retrieveIngredientsForDish(dish);
+ pantryStock = retrieveStockFromStorage();
+
+ //for each ingredient that is used in the dish, update the stock of ingredient left.
+ for (Ingredient dishIngredient : dishIngredients) {
+ Ingredient usedIngredientFromStock = getIngredient(dishIngredient);
+ String unit = extractUnit(dishIngredient.getQuantity());
+ int stockQuantity = extractQuantity(usedIngredientFromStock);
+ int usedQuantity = extractQuantity(dishIngredient);
+
+ usedIngredientFromStock.setQuantity(String.valueOf(stockQuantity-usedQuantity)+unit);
+ }
+ //TODO: store pantryStock to storage
+ }
+
+ /**
+ * Extracts the quantity from the given ingredient quantity string.
+ *
+ * @param ingredient The ingredient from which quantity is extracted.
+ * @return The extracted quantity as an integer.
+ */
+ private static int extractQuantity(Ingredient ingredient) {
+ return Integer.parseInt(ingredient.getQuantity()
+ .replaceAll("[^0-9]", ""));
+ }
+
+ /**
+ * Extracts the unit from the given quantity string.
+ *
+ * @param qty The quantity string.
+ * @return The extracted unit string.
+ */
+ public String extractUnit(String qty) {
+ return qty.replaceAll("[0-9]", "");}
+
+ /**
+ * Retrieves the ingredient used in the ordered dish from pantryStock.
+ *
+ * @param dishIngredient The ingredient used in the ordered dish.
+ * @return The corresponding ingredient in pantryStock.
+ */
+ private Ingredient getIngredient(Ingredient dishIngredient) {
+ return pantryStock.stream()
+ .filter(ingredient -> ingredient.getName().equals(dishIngredient.getName()))
+ .findFirst()
+ .orElse(null);
+ }
+
+ /**
+ * Checks the availability of dishes based on ingredient stock.
+ */
+ public void checkDishAvailability(){
+ for (Dish dish : menuItems) {
+ ui.printLine();
+ ui.showToUser("Dish: " + dish.getName());
+ int numberOfDishes = checkIngredientAvailability(dish);
+ ui.showToUser("Available Dishes: " + numberOfDishes);
+ ui.printLine();
+ }
+ }
+
+ /**
+ * Checks the availability of ingredients in the pantry for a given dish order.
+ *
+ * @param dish The dish being ordered.
+ */
+ public int checkIngredientAvailability(Dish dish) {
+ int maxNumofDish = Integer.MAX_VALUE;
+ ArrayList dishIngredients = retrieveIngredientsForDish(dish.getName());
+
+ for (Ingredient dishIngredient : dishIngredients) {
+ int numOfDish = calculateNumOfDish(dishIngredient);
+ maxNumofDish = Math.min(numOfDish, maxNumofDish);
+
+ if (numOfDish == 0) {
+ handleRestock(dishIngredient);
+ }
+ }
+
+ return maxNumofDish;
+ }
+
+ /**
+ * Calculates the number of dishes that can be prepared with the available ingredients.
+ *
+ * @param dishIngredient The ingredient used in the ordered dish.
+ * @return The number of dishes that can be prepared.
+ */
+ private int calculateNumOfDish(Ingredient dishIngredient) {
+ Ingredient usedIngredientFromStock = getIngredient(dishIngredient);
+ if (usedIngredientFromStock == null) {
+ return 0;
+ }
+
+ int currentQuantity = extractQuantity(usedIngredientFromStock);
+ int usedQuantity = extractQuantity(dishIngredient);
+ return currentQuantity / usedQuantity;
+ }
+
+ /**
+ * Handles the case when restocking is required for a specific ingredient.
+ *
+ * @param dishIngredient The ingredient for which restocking is needed.
+ */
+ private void handleRestock(Ingredient dishIngredient) {
+ String unit = extractUnit(dishIngredient.getQuantity());
+ String dishIngredientName = dishIngredient.getName();
+
+ ui.showToUser("Please Restock: " + dishIngredientName);
+ Ingredient stockIngredient = getIngredient(dishIngredient);
+ int currentQuantity = (stockIngredient == null) ? 0 : extractQuantity(stockIngredient);
+
+ ui.showToUser("Current " + dishIngredientName + ": " + currentQuantity + unit);
+ ui.showToUser("Needed " + dishIngredientName + ": " + extractQuantity(dishIngredient) + unit);
+ }
+
+
+ /**
+ * Retrieves the ingredients for a specific ordered dish.
+ *
+ * @param orderedDish The name of the ordered dish.
+ * @return The list of ingredients for the ordered dish.
+ */
+ public ArrayList retrieveIngredientsForDish(String orderedDish){
+ ArrayList menuItems = dummyData();
+ ArrayList dishIngredients = new ArrayList<>();
+
+ //retrieving the ingredients for orderedDish
+ for (Dish dish : menuItems) {
+ if (dish.getName().equals(orderedDish)) {
+ dishIngredients.addAll(dish.getIngredients());
+ break;
+ }
+ }
+ return dishIngredients;
+ }
+
+ /**
+ * Retrieves the current stock of ingredients from storage.
+ *
+ * @return The list of ingredients representing the current stock.
+ */
+ public ArrayList retrieveStockFromStorage () {
+ //dummy data for pantry stock which will be replaced with storage data
+ ArrayList pantryStock = new ArrayList<>(Arrays.asList(new Ingredient("Rice", "600g"),
+ new Ingredient("Chicken", "150g"), new Ingredient("Bread", "2 pieces"),
+ new Ingredient("Lettuce", "50g")));
+ return pantryStock;
+ }
+
+ /**
+ * Provides dummy data for menu items. This function will be removed when storage is implemented.
+ *
+ * @return The list of dummy menu items.
+ */
+ private ArrayList dummyData() {
+ //dummy data for pantry stock which will be replaced with storage data
+ menuItems = new ArrayList<>();
+ menuItems.add(new Dish("Chicken Rice",
+ new ArrayList<>(Arrays.asList(new Ingredient("Rice", "300g"),
+ new Ingredient("Chicken", "100g"))), 8.0F));
+ menuItems.add(new Dish("Chicken Sandwich",
+ new ArrayList<>(Arrays.asList(new Ingredient("Lettuce", "50g"),
+ new Ingredient("Chicken", "50g"))), 5.0F));
+ return menuItems;
+ }
+}
+
+
+
diff --git a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
index 9fefb107eb..202942db01 100644
--- a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
+++ b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
@@ -2,7 +2,7 @@
public class Ingredient {
private final String name;
- private final String quantity;
+ private String quantity;
public Ingredient(String name) {
this.name = name;
@@ -22,6 +22,10 @@ public String getQuantity() {
return quantity;
}
+ public void setQuantity(String newQuantity) {
+ this.quantity = newQuantity;
+ }
+
@Override
public String toString() {
return name + " - " + quantity;
From 008f089f8a0882f0658457c72e663fcc3078c2ad Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Sun, 22 Oct 2023 23:26:42 +0800
Subject: [PATCH 169/870] Update .gitignore file
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 2873e189e1..7039d1ae76 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,4 @@ bin/
/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
+META-INF/MANIFEST.MF
From bf777c46f6b1718b5e939b83e6b6d710b37ff8ff Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Sun, 22 Oct 2023 23:27:30 +0800
Subject: [PATCH 170/870] build.gradle: Enable assertions
---
build.gradle | 1 +
1 file changed, 1 insertion(+)
diff --git a/build.gradle b/build.gradle
index 1dc381723f..19ef50a23a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -43,4 +43,5 @@ checkstyle {
run{
standardInput = System.in
+ enableAssertions = true
}
From bf9bd2b8a6eb33b17431bede88dc2a51f58c49c1 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Sun, 22 Oct 2023 23:54:08 +0800
Subject: [PATCH 171/870] Add Order Class
---
src/main/java/seedu/cafectrl/Order.java | 38 +++++++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 src/main/java/seedu/cafectrl/Order.java
diff --git a/src/main/java/seedu/cafectrl/Order.java b/src/main/java/seedu/cafectrl/Order.java
new file mode 100644
index 0000000000..84a5e25709
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/Order.java
@@ -0,0 +1,38 @@
+package seedu.cafectrl;
+
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.data.dish.Ingredient;
+
+import java.util.ArrayList;
+
+public class Order {
+ protected String dishName;
+ protected int dishQty;
+ protected Dish orderedDish;
+ protected ArrayList usedIngredientList;
+ protected boolean isComplete = false;
+ protected float totalOrderCost;
+
+ public Order(String dishName, int dishQty) {
+ this.dishName = dishName;
+ this.dishQty = dishQty;
+ }
+
+ public Order(String dishName, int dishQty, ArrayList usedIngredientList) {
+ this.dishName = dishName;
+ this.dishQty = dishQty;
+ this.usedIngredientList = usedIngredientList;
+ }
+
+ public Order(String dishName, int dishQty, ArrayList usedIngredientList, float totalOrderCost) {
+ this.dishName = dishName;
+ this.dishQty = dishQty;
+ this.usedIngredientList = usedIngredientList;
+ this.totalOrderCost = totalOrderCost;
+ }
+
+ public void setComplete() {
+ this.isComplete = true;
+ }
+
+}
From 6d2ba2ce36b19daf8b6baf44842569ee9ec923a8 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 23 Oct 2023 01:56:59 +0800
Subject: [PATCH 172/870] Add parser support for Order
---
.../cafectrl/command/AddOrderCommand.java | 30 +++++
.../java/seedu/cafectrl/parser/Parser.java | 110 ++++++++++++++++++
2 files changed, 140 insertions(+)
create mode 100644 src/main/java/seedu/cafectrl/command/AddOrderCommand.java
diff --git a/src/main/java/seedu/cafectrl/command/AddOrderCommand.java b/src/main/java/seedu/cafectrl/command/AddOrderCommand.java
new file mode 100644
index 0000000000..2c504748af
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/command/AddOrderCommand.java
@@ -0,0 +1,30 @@
+package seedu.cafectrl.command;
+
+import seedu.cafectrl.Order;
+import seedu.cafectrl.OrderList;
+import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.dish.Dish;
+import seedu.cafectrl.ui.Ui;
+
+public class AddOrderCommand extends Command {
+ public static final String COMMAND_WORD = "add_order";
+ public static final String MESSAGE_USAGE = COMMAND_WORD
+ + ": Add dish to menu\n"
+ + "Parameters: DISH_NAME, PRICE, INGREDIENT1_NAME, INGREDIENT1_QTY "
+ + "[,INGREDIENT1_NAME, INGREDIENT1_QTY...] \n"
+ + "Example: " + COMMAND_WORD
+ + " name/chicken rice price/3.00 ingredient/rice qty/1 cup, ingredient/chicken qty/100g";
+ Order order;
+ public AddOrderCommand(Order order) {
+ this.order = order;
+ }
+ /*@Override
+ public void execute(OrderList orderList, Ui ui) {
+ orderList.addOrder(order);
+ ui.printAddDishMessage(dish);
+ }*/
+ @Override
+ public void execute(Menu menu, Ui ui) {
+
+ }
+}
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index a4fd7b8f98..47fa23e549 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -1,5 +1,6 @@
package seedu.cafectrl.parser;
+import seedu.cafectrl.Order;
import seedu.cafectrl.command.AddDishCommand;
import seedu.cafectrl.command.Command;
import seedu.cafectrl.command.IncorrectCommand;
@@ -8,6 +9,7 @@
import seedu.cafectrl.command.ExitCommand;
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.command.ListMenuCommand;
+import seedu.cafectrl.command.AddOrderCommand;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.data.Menu;
@@ -40,6 +42,9 @@ public class Parser {
+ "price/([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))? "
+ "(ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+"
+ "(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)";
+ private static final String ADD_ORDER_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) "
+ + "qty/([A-Za-z0-9\\s]+)";
+ public static final int ORDER_QTY_MATCHER_GROUP_NUM = 2;
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
@@ -82,6 +87,9 @@ public static Command parseCommand(Menu menu, String userInput) {
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
+ case AddOrderCommand.COMMAND_WORD:
+ return prepareOrder(menu, arguments);
+
default:
return new IncorrectCommand(Messages.UNKNOWN_COMMAND_MESSAGE);
}
@@ -251,6 +259,108 @@ private static Command prepareDelete(Menu menu, String arguments) {
return new DeleteDishCommand(dishIndex);
}
+ private static Command prepareOrder(Menu menu, String arguments) {
+ final Pattern addOrderArgumentPatter = Pattern.compile(ADD_ORDER_ARGUMENT_STRING);
+ Matcher matcher = addOrderArgumentPatter.matcher(arguments);
+
+ // Checks whether the overall pattern of add order arguments is correct
+ if (!matcher.matches()) {
+ return new IncorrectCommand("Error: Incorrect format for the add order command.\n"
+ + AddOrderCommand.MESSAGE_USAGE);
+ }
+
+ try {
+ // To retrieve specific arguments from arguments
+ String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_NUM);
+ //System.out.println("Dish Name: " + dishName);
+ int dishQty = Integer.parseInt(matcher.group(ORDER_QTY_MATCHER_GROUP_NUM));
+ //System.out.println("Dish QTY: " + dishQty);
+
+ Dish orderedDish = getDishInMenu(dishName, menu);
+ if (orderedDish == null) {
+ return new IncorrectCommand(Messages.DISH_NOT_FOUND);
+ }
+ //System.out.println("Ordered Dish: " + orderedDish);
+
+ ArrayList usedIngredientList = getIngredientList(orderedDish, dishQty);
+ //System.out.println("IngredientList: " + usedIngredientList);
+ float totalOrderCost = getDishPrice(orderedDish, dishQty);
+ //System.out.println("Total Order Cost: $" + totalOrderCost + "0");
+ Order order = new Order(dishName, dishQty, usedIngredientList, totalOrderCost);
+ System.out.println(order);
+
+ return new AddOrderCommand(order);
+ } catch (Exception e) {
+ return new IncorrectCommand("MESSAGE_INVALID_ADD_ORDER_COMMAND_FORMAT"
+ + AddOrderCommand.MESSAGE_USAGE + e.getMessage());
+ }
+ }
+
+ private static Dish getDishInMenu(String dishName, Menu menu) {
+ String formattedDishName = dishName.toLowerCase().trim();
+ for (int i = 0; i < menu.getSize(); i++) {
+ String menuDishName = menu.getDish(i).getName();
+ String formattedMenuDishName = menuDishName.toLowerCase().trim();
+ if (formattedMenuDishName.equals(formattedDishName)){
+ return menu.getDish(i);
+ }
+ }
+ return null;
+ }
+
+ private static ArrayList getIngredientList(Dish orderedDish, int dishQty) {
+ ArrayList dishIngredient = new ArrayList<>();
+ for (Ingredient ingredient : orderedDish.getIngredients()) {
+ String ingredientName = ingredient.getName();
+ int ingredientQty = Integer.parseInt(ingredient.getQuantity()) * dishQty;
+ dishIngredient.add(new Ingredient(ingredientName, String.valueOf(ingredientQty)));
+ }
+ return dishIngredient;
+ }
+
+ private static float getDishPrice(Dish orderedDish, int dishQty) {
+ float dishCost = orderedDish.getPrice();
+ float totalOrderCost = dishCost * dishQty;
+ return totalOrderCost;
+ }
+
+ /*private static ArrayList checkIngredientStock(Dish orderedDish, int dishQty) {
+ ArrayList ingredientList = orderedDish.getIngredients();
+ ArrayList usedIngredientList = new ArrayList<>();
+ for (int i = 0; i < ingredientList.size(); i++) {
+ getIngredientInStore(ingredientList.get(i), dishQty, orderedDish, usedIngredientList);
+ }
+ return usedIngredientList;
+ }
+
+ private static void getIngredientInStore(Ingredient dishIngredient, int dishQty, Dish orderedDish, ArrayList usedIngredientList) {
+ String ingredientName = dishIngredient.getName();
+ String formattedIngredientName = ingredientName.toLowerCase().trim();
+ int ingredientUsagePerDish = Integer.parseInt(dishIngredient.getQuantity());
+ int totalIngredientUsage = dishQty * ingredientUsagePerDish;
+
+ for (int i = 0; i < pantry.getSize(); i++) {
+ String storedIngredientName = pantry.getIngredient(i).getName();
+ String formattedStoredIngredientName = menuDishName.toLowerCase().trim();
+ if (!formattedStoredIngredientName.equals(formattedIngredientName) || !isIngredientEnough(totalIngredientUsage, i)){
+ System.out.println("Error not enough stuff");
+ return;
+ }
+ usedIngredientList.add(new Ingredient(ingredientName, String.valueOf(totalIngredientUsage)));
+ }
+
+ }
+
+ private static boolean isIngredientEnough(int totalIngredientUsage, int storedIndex) {
+ int storedQuantity = Integer.parseInt(storeroom.getIngredient(storedIndex).getQuantity());
+ if (storedQuantity >= totalIngredientUsage) {
+ return true;
+ } else {
+ return false;
+ }
+ }*/
+
+
/**
* Parses the given arguments string to identify task index number.
*
From 999da2ca70324fe354af44f98cc2ae9e7ced7169 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 23 Oct 2023 01:57:28 +0800
Subject: [PATCH 173/870] Add toString() in Order.java
---
src/main/java/seedu/cafectrl/Order.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/main/java/seedu/cafectrl/Order.java b/src/main/java/seedu/cafectrl/Order.java
index 84a5e25709..6a145a9d3d 100644
--- a/src/main/java/seedu/cafectrl/Order.java
+++ b/src/main/java/seedu/cafectrl/Order.java
@@ -31,6 +31,12 @@ public Order(String dishName, int dishQty, ArrayList usedIngredientL
this.totalOrderCost = totalOrderCost;
}
+ public String toString() {
+ return "Order: " + dishName + " Quantity: "+ dishQty
+ + "\nIngredientList: " + usedIngredientList
+ + "\nTotal Order Cost: $" + totalOrderCost;
+ }
+
public void setComplete() {
this.isComplete = true;
}
From ce93be786fd23cac0983576e9654e2976dca38e8 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 23 Oct 2023 02:01:48 +0800
Subject: [PATCH 174/870] Update Messages with UI support for Order
---
src/main/java/seedu/cafectrl/ui/Messages.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 7122b36dd2..0accae6977 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -29,10 +29,12 @@ public class Messages {
public static final String LIST_MENU_MESSAGE = "| Ah, behold, the grand menu of delights! |";
public static final String MENU_EMPTY_MESSAGE = "It seems our menu is currently taking a break. "
- + "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?";
+ + "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?";
public static final String MENU_TOP = "+-----------------------------------------+";
public static final String MENU_CORNER = "+--------------------------+--------------+";
- public static final String MENU_TITLE = "| Dish Name | Price |";
+ public static final String MENU_TITLE = "| Dish Name | Price |";
+ public static final String DISH_NOT_FOUND = "I'm sorry, but it appears that dish is so exclusive "
+ + "it hasn't even made it to our menu yet!";
public static final String ADD_DISH_MESSAGE = "You have added the following dish...";
From cabad889ab555b6563a97a75e0075e5911d512ea Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 23 Oct 2023 12:05:12 +0800
Subject: [PATCH 175/870] Create OrderList.java
---
src/main/java/seedu/cafectrl/OrderList.java | 29 +++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 src/main/java/seedu/cafectrl/OrderList.java
diff --git a/src/main/java/seedu/cafectrl/OrderList.java b/src/main/java/seedu/cafectrl/OrderList.java
new file mode 100644
index 0000000000..c28b2164b9
--- /dev/null
+++ b/src/main/java/seedu/cafectrl/OrderList.java
@@ -0,0 +1,29 @@
+package seedu.cafectrl;
+
+import java.util.ArrayList;
+
+public class OrderList {
+ protected ArrayList orderList;
+ public OrderList() {
+ this.orderList = new ArrayList();
+ }
+ public OrderList(ArrayList orderList) {
+ this.orderList = orderList;
+ }
+ public ArrayList getOrderList() {
+ return orderList;
+ }
+ public int getSize() {
+ return orderList.size();
+ }
+ public Order getOrder(int orderID) {
+ return orderList.get(orderID);
+ }
+ public void removeOrder(int orderID) {
+ orderList.remove(orderID);
+ }
+
+ public void addOrder(Order order) {
+ orderList.add(order);
+ }
+}
From 9741101389b74a91575214cfd166abff8b62a3a3 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 23 Oct 2023 12:08:41 +0800
Subject: [PATCH 176/870] Update code to comply with Gradle
---
src/main/java/seedu/cafectrl/command/AddOrderCommand.java | 2 --
src/main/java/seedu/cafectrl/parser/Parser.java | 8 +++++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/AddOrderCommand.java b/src/main/java/seedu/cafectrl/command/AddOrderCommand.java
index 2c504748af..940ea53483 100644
--- a/src/main/java/seedu/cafectrl/command/AddOrderCommand.java
+++ b/src/main/java/seedu/cafectrl/command/AddOrderCommand.java
@@ -1,9 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.Order;
-import seedu.cafectrl.OrderList;
import seedu.cafectrl.data.Menu;
-import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Ui;
public class AddOrderCommand extends Command {
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 47fa23e549..a595f7bb84 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -38,13 +38,13 @@ public class Parser {
public static final int DISH_NAME_MATCHER_GROUP_NUM = 1;
public static final int PRICE_MATCHER_GROUP_NUM = 2;
public static final int INGREDIENT_LIST_MATCHER_GROUP_NUM = 4;
+ public static final int ORDER_QTY_MATCHER_GROUP_NUM = 2;
private static final String ADD_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) "
+ "price/([+-]?(?=\\.\\d|\\d)(?:\\d+)?(?:\\.?\\d*))(?:[Ee]([+-]?\\d+))? "
+ "(ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+"
+ "(?:, ingredient/[A-Za-z0-9\\s]+ qty/[A-Za-z0-9\\s]+)*)";
private static final String ADD_ORDER_ARGUMENT_STRING = "name/([A-Za-z0-9\\s]+) "
+ "qty/([A-Za-z0-9\\s]+)";
- public static final int ORDER_QTY_MATCHER_GROUP_NUM = 2;
private static final String LIST_INGREDIENTS_ARGUMENT_STRING = "(\\d+)";
private static final String DELETE_ARGUMENT_STRING = "(\\d+)";
private static final String EDIT_PRICE_ARGUMENT_STRING = "index/(\\d+) price/(\\d+(\\.\\d+)?)";
@@ -333,7 +333,8 @@ private static float getDishPrice(Dish orderedDish, int dishQty) {
return usedIngredientList;
}
- private static void getIngredientInStore(Ingredient dishIngredient, int dishQty, Dish orderedDish, ArrayList usedIngredientList) {
+ private static void getIngredientInStore(Ingredient dishIngredient, int dishQty,
+ Dish orderedDish, ArrayList usedIngredientList) {
String ingredientName = dishIngredient.getName();
String formattedIngredientName = ingredientName.toLowerCase().trim();
int ingredientUsagePerDish = Integer.parseInt(dishIngredient.getQuantity());
@@ -342,7 +343,8 @@ private static void getIngredientInStore(Ingredient dishIngredient, int dishQty,
for (int i = 0; i < pantry.getSize(); i++) {
String storedIngredientName = pantry.getIngredient(i).getName();
String formattedStoredIngredientName = menuDishName.toLowerCase().trim();
- if (!formattedStoredIngredientName.equals(formattedIngredientName) || !isIngredientEnough(totalIngredientUsage, i)){
+ if (!formattedStoredIngredientName.equals(formattedIngredientName)
+ || !isIngredientEnough(totalIngredientUsage, i)){
System.out.println("Error not enough stuff");
return;
}
From 37a70ddcb2b047143d26d65a8cb7dfb94cf64716 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Mon, 23 Oct 2023 12:20:57 +0800
Subject: [PATCH 177/870] Move LINE_STRING from Ui.java to Messages.java
---
src/main/java/seedu/cafectrl/ui/Messages.java | 1 +
src/main/java/seedu/cafectrl/ui/Ui.java | 3 +--
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 729e37a484..dff0554b45 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.ui;
public class Messages {
+ public static final String LINE_STRING = "-----------------------------------------------------";
/**
* Greeting messages
*/
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 005742131d..ceb50e1a33 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -8,7 +8,6 @@
public class Ui {
public static final int OFFSET_LIST_INDEX = 1;
- public static final String LINE_STRING = "-----------------------------------------------------";
private final Scanner scanner;
/**
@@ -19,7 +18,7 @@ public Ui() {
}
public void printLine() {
- showToUser(LINE_STRING);
+ showToUser(Messages.LINE_STRING);
}
public String receiveUserInput() {
From 756e97ebc15c91ca89be53688609d5a60b6ec466 Mon Sep 17 00:00:00 2001
From: ziyi105
Date: Mon, 23 Oct 2023 12:21:29 +0800
Subject: [PATCH 178/870] Complete helpCommandTest for execute
---
.../cafectrl/command/HelpCommandTest.java | 25 ++++++++++++++++---
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
index 9613297d89..7cafb347b3 100644
--- a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
@@ -2,34 +2,51 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
import java.util.ArrayList;
import java.util.Arrays;
-//import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
class HelpCommandTest {
@Test
void execute_validInput_editPrice() {
- ArrayList actualOutput = new ArrayList<>();
+ ArrayList actualOutputs = new ArrayList<>();
Menu menu = new Menu();
Ui ui = new Ui() {
@Override
public void showToUser(String... message) {
- actualOutput.addAll(Arrays.asList(message));
+ actualOutputs.addAll(Arrays.asList(message));
}
@Override
public void showToUserWithSpaceBetweenLines(String... message) {
- actualOutput.addAll(Arrays.asList(message));
+ actualOutputs.addAll(Arrays.asList(message));
}
};
HelpCommand helpCommand = new HelpCommand();
helpCommand.execute(menu, ui);
+ int numOfLines = 8;
+
+ ArrayList expectedOutputs = new ArrayList<>();
+
+ expectedOutputs.add(Messages.LINE_STRING);
+ expectedOutputs.add(Messages.LIST_OF_COMMANDS);
+ expectedOutputs.add(Messages.INSTRUCTION_ON_COMMAND_FORMAT);
+ expectedOutputs.add(Messages.ADD_DISH_GUIDE);
+ expectedOutputs.add(Messages.LIST_MENU_GUIDE);
+ expectedOutputs.add(Messages.LIST_INGREDIENTS_GUIDE);
+ expectedOutputs.add(Messages.DELETE_GUIDE);
+ expectedOutputs.add(Messages.EDIT_PRICE_GUIDE);
+
+ for (int i = 0; i < numOfLines; i++) {
+ assertEquals(expectedOutputs.get(i), actualOutputs.get(i));
+ }
}
}
From c184350348434e9d36140d1010ef592d6f98e4d2 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 23 Oct 2023 12:31:20 +0800
Subject: [PATCH 179/870] Add JavaDoc for Order in Parser
---
.../java/seedu/cafectrl/parser/Parser.java | 73 ++++++++-----------
1 file changed, 29 insertions(+), 44 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index a595f7bb84..70e6625c37 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -259,6 +259,13 @@ private static Command prepareDelete(Menu menu, String arguments) {
return new DeleteDishCommand(dishIndex);
}
+ /**
+ * Parses arguments in the context of the Delete command.
+ *
+ * @param menu menu of the current session
+ * @param arguments string that matches group arguments
+ * @return AddOrderCommand if command is valid, IncorrectCommand otherwise
+ */
private static Command prepareOrder(Menu menu, String arguments) {
final Pattern addOrderArgumentPatter = Pattern.compile(ADD_ORDER_ARGUMENT_STRING);
Matcher matcher = addOrderArgumentPatter.matcher(arguments);
@@ -272,20 +279,15 @@ private static Command prepareOrder(Menu menu, String arguments) {
try {
// To retrieve specific arguments from arguments
String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_NUM);
- //System.out.println("Dish Name: " + dishName);
int dishQty = Integer.parseInt(matcher.group(ORDER_QTY_MATCHER_GROUP_NUM));
- //System.out.println("Dish QTY: " + dishQty);
Dish orderedDish = getDishInMenu(dishName, menu);
if (orderedDish == null) {
return new IncorrectCommand(Messages.DISH_NOT_FOUND);
}
- //System.out.println("Ordered Dish: " + orderedDish);
ArrayList usedIngredientList = getIngredientList(orderedDish, dishQty);
- //System.out.println("IngredientList: " + usedIngredientList);
float totalOrderCost = getDishPrice(orderedDish, dishQty);
- //System.out.println("Total Order Cost: $" + totalOrderCost + "0");
Order order = new Order(dishName, dishQty, usedIngredientList, totalOrderCost);
System.out.println(order);
@@ -296,6 +298,13 @@ private static Command prepareOrder(Menu menu, String arguments) {
}
}
+ /**
+ * Checks if the ordered dish exist in the menu and returns the menu index if exist
+ *
+ * @param dishName Name of the ordered dish
+ * @param menu menu of the current session
+ * @return index of the dish in menu if exists, null if not found
+ */
private static Dish getDishInMenu(String dishName, Menu menu) {
String formattedDishName = dishName.toLowerCase().trim();
for (int i = 0; i < menu.getSize(); i++) {
@@ -308,6 +317,14 @@ private static Dish getDishInMenu(String dishName, Menu menu) {
return null;
}
+ /**
+ * Gets and prepares the ingredients used in the dish.
+ * Calculates the total ingredient used and stores in an Ingredient ArrayList
+ *
+ * @param orderedDish Dish object of the ordered dish
+ * @param dishQty Number of the ordered dish requested
+ * @return Arraylist of Ingredients
+ */
private static ArrayList getIngredientList(Dish orderedDish, int dishQty) {
ArrayList dishIngredient = new ArrayList<>();
for (Ingredient ingredient : orderedDish.getIngredients()) {
@@ -318,51 +335,19 @@ private static ArrayList getIngredientList(Dish orderedDish, int dis
return dishIngredient;
}
+ /**
+ * Calculates the total price of the order
+ *
+ * @param orderedDish Dish object of the ordered dish
+ * @param dishQty Number of the ordered dish requested
+ * @return Total calculated cost
+ */
private static float getDishPrice(Dish orderedDish, int dishQty) {
float dishCost = orderedDish.getPrice();
float totalOrderCost = dishCost * dishQty;
return totalOrderCost;
}
- /*private static ArrayList checkIngredientStock(Dish orderedDish, int dishQty) {
- ArrayList ingredientList = orderedDish.getIngredients();
- ArrayList usedIngredientList = new ArrayList<>();
- for (int i = 0; i < ingredientList.size(); i++) {
- getIngredientInStore(ingredientList.get(i), dishQty, orderedDish, usedIngredientList);
- }
- return usedIngredientList;
- }
-
- private static void getIngredientInStore(Ingredient dishIngredient, int dishQty,
- Dish orderedDish, ArrayList usedIngredientList) {
- String ingredientName = dishIngredient.getName();
- String formattedIngredientName = ingredientName.toLowerCase().trim();
- int ingredientUsagePerDish = Integer.parseInt(dishIngredient.getQuantity());
- int totalIngredientUsage = dishQty * ingredientUsagePerDish;
-
- for (int i = 0; i < pantry.getSize(); i++) {
- String storedIngredientName = pantry.getIngredient(i).getName();
- String formattedStoredIngredientName = menuDishName.toLowerCase().trim();
- if (!formattedStoredIngredientName.equals(formattedIngredientName)
- || !isIngredientEnough(totalIngredientUsage, i)){
- System.out.println("Error not enough stuff");
- return;
- }
- usedIngredientList.add(new Ingredient(ingredientName, String.valueOf(totalIngredientUsage)));
- }
-
- }
-
- private static boolean isIngredientEnough(int totalIngredientUsage, int storedIndex) {
- int storedQuantity = Integer.parseInt(storeroom.getIngredient(storedIndex).getQuantity());
- if (storedQuantity >= totalIngredientUsage) {
- return true;
- } else {
- return false;
- }
- }*/
-
-
/**
* Parses the given arguments string to identify task index number.
*
From 44b84aacf3a7c12558a9a63902a1e97604c0c0d7 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Mon, 23 Oct 2023 15:13:01 +0800
Subject: [PATCH 180/870] ListMenuCommand.java: add space around operator
---
src/main/java/seedu/cafectrl/command/ListMenuCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index 22c2d5f657..a1d482504b 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -37,7 +37,7 @@ public void printFullMenu(Menu menu, Ui ui) {
ui.showToUser(Messages.MENU_TOP, Messages.LIST_MENU_MESSAGE,
Messages.MENU_CORNER, Messages.MENU_TITLE, Messages.MENU_CORNER);
for(int i =0; i < menu.getSize(); i++) {
- String indexNum = String.valueOf(i+1);
+ String indexNum = String.valueOf(i + 1);
String dishName = menu.getDish(i).getName();
String dishPrice = dollarValue.format(menu.getDish(i).getPrice());
ui.formatListMenu(indexNum + ". " + dishName," $" + dishPrice);
From efdc7cab49f6c35295221cee69a79ca1e4ef76e1 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Mon, 23 Oct 2023 15:19:58 +0800
Subject: [PATCH 181/870] Parser.java: update formatting of single line comment
---
src/main/java/seedu/cafectrl/parser/Parser.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index dcc358b411..cf849b4ffa 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -90,9 +90,7 @@ public static Command parseCommand(Menu menu, String userInput) {
}
}
- /**
- * All prepareCommand Classes
- */
+ /** All prepareCommand Classes */
private static Command prepareListMenu() {
return new ListMenuCommand();
}
From 2cd77bfba70bf778f72bcde41df599c94a610cc2 Mon Sep 17 00:00:00 2001
From: ziyi105 <82555990+ziyi105@users.noreply.github.com>
Date: Mon, 23 Oct 2023 15:24:11 +0800
Subject: [PATCH 182/870] Messages.java: update string spliting indentation
---
src/main/java/seedu/cafectrl/ui/Messages.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index dff0554b45..8705df3001 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -19,7 +19,7 @@ public class Messages {
*/
public static final String LIST_MENU_MESSAGE = "| Ah, behold, the grand menu of delights! |";
public static final String MENU_EMPTY_MESSAGE = "It seems our menu is currently taking a break. "
- + "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?";
+ + "Let's give it a wake-up call and fill 'er up with delectable delights, shall we?";
public static final String MENU_TOP = "+-----------------------------------------+";
public static final String MENU_CORNER = "+--------------------------+--------------+";
public static final String MENU_TITLE = "| Dish Name | Price |";
From d4e717104a76ff44bd25aa1ead7a97fb824f026c Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Mon, 23 Oct 2023 18:03:36 +0800
Subject: [PATCH 183/870] Change exception handling for prepareAdd logic
---
.../java/seedu/cafectrl/parser/Parser.java | 41 ++++++++-----------
1 file changed, 16 insertions(+), 25 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index a4fd7b8f98..d2a2c37876 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -131,49 +131,42 @@ private static Command prepareAdd(String arguments) {
final Pattern addArgumentPatter = Pattern.compile(ADD_ARGUMENT_STRING);
Matcher matcher = addArgumentPatter.matcher(arguments);
- // Checks whether the overall pattern of add arguments is correct
- if (!matcher.matches()) {
- return new IncorrectCommand("Error: Incorrect format for the add command.\n"
- + AddDishCommand.MESSAGE_USAGE);
- }
-
try {
+ // Checks whether the overall pattern of add arguments is correct
+ if (!matcher.matches()) {
+ return new IncorrectCommand("Error: Incorrect format for the add command.\n"
+ + AddDishCommand.MESSAGE_USAGE);
+ }
+
// To retrieve specific arguments from arguments
String dishName = matcher.group(DISH_NAME_MATCHER_GROUP_NUM);
float price = Float.parseFloat(matcher.group(PRICE_MATCHER_GROUP_NUM));
String ingredientsListString = matcher.group(INGREDIENT_LIST_MATCHER_GROUP_NUM);
- IncorrectCommand incorrectCommand1 = checkNegativePrice(price);
- if (incorrectCommand1 != null) {
- return incorrectCommand1;
- }
+ checkNegativePrice(price);
// Capture the list of ingredients
ArrayList ingredients = new ArrayList<>();
- IncorrectCommand incorrectCommand2 = ingredientParsing(ingredientsListString, ingredients);
- if (incorrectCommand2 != null) {
- return incorrectCommand2;
- }
+ ingredientParsing(ingredientsListString, ingredients);
Dish dish = new Dish(dishName, ingredients, price);
return new AddDishCommand(dish);
- } catch (Exception e) {
- return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT"
+ } catch (IllegalArgumentException e) {
+ return new IncorrectCommand("Error: Incorrect format for the ingredients.\n"
+ AddDishCommand.MESSAGE_USAGE);
}
}
-
- private static IncorrectCommand checkNegativePrice(float price) {
+ /** to be removed once the new regex is implemented because new regex only allows positive prices*/
+ private static void checkNegativePrice(float price) throws IllegalArgumentException {
if (price < 0) {
- return new IncorrectCommand("MESSAGE_INVALID_ADD_COMMAND_FORMAT"
- + AddDishCommand.MESSAGE_USAGE);
+ throw new IllegalArgumentException();
}
- return null;
}
- private static IncorrectCommand ingredientParsing(String ingredientsListString, ArrayList ingredients) {
+ private static void ingredientParsing(String ingredientsListString, ArrayList ingredients)
+ throws IllegalArgumentException {
String[] ingredientListInputText = {ingredientsListString};
//check if there is more than 1 ingredient
@@ -187,8 +180,7 @@ private static IncorrectCommand ingredientParsing(String ingredientsListString,
Matcher ingredientMatcher = ingredientPattern.matcher(inputIngredientText);
if (!ingredientMatcher.matches()) {
- return new IncorrectCommand("Error: Incorrect format for the ingredients\n"
- + AddDishCommand.MESSAGE_USAGE);
+ throw new IllegalArgumentException();
}
String ingredientName = ingredientMatcher.group(INGREDIENT_NAME_REGEX_GROUP_LABEL);
@@ -198,7 +190,6 @@ private static IncorrectCommand ingredientParsing(String ingredientsListString,
ingredients.add(ingredient);
}
- return null;
}
From 974c5c0d82e8a75ac4fe1e985f5eb03bc49923d1 Mon Sep 17 00:00:00 2001
From: Cazh1
Date: Mon, 23 Oct 2023 18:07:20 +0800
Subject: [PATCH 184/870] Update ListMenu Code quality
---
src/main/java/seedu/cafectrl/command/ListMenuCommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index a1d482504b..caf6407b8f 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -36,7 +36,7 @@ public void printEmptyMenu(Ui ui) {
public void printFullMenu(Menu menu, Ui ui) {
ui.showToUser(Messages.MENU_TOP, Messages.LIST_MENU_MESSAGE,
Messages.MENU_CORNER, Messages.MENU_TITLE, Messages.MENU_CORNER);
- for(int i =0; i < menu.getSize(); i++) {
+ for (int i = 0; i < menu.getSize(); i++) {
String indexNum = String.valueOf(i + 1);
String dishName = menu.getDish(i).getName();
String dishPrice = dollarValue.format(menu.getDish(i).getPrice());
From baf4a1b83f4c0c988a4cd37d3c8feece84a3e541 Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Mon, 23 Oct 2023 18:26:41 +0800
Subject: [PATCH 185/870] Change error messages and minor change to
AddDishCommand class
---
src/main/java/seedu/cafectrl/command/AddDishCommand.java | 5 +++--
src/main/java/seedu/cafectrl/parser/Parser.java | 4 ++--
src/main/java/seedu/cafectrl/ui/Messages.java | 4 +---
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/command/AddDishCommand.java b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
index 38aa723e3c..263e2a4dc3 100644
--- a/src/main/java/seedu/cafectrl/command/AddDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
@@ -14,8 +14,9 @@ public class AddDishCommand extends Command {
+ "Parameters: DISH_NAME, PRICE, INGREDIENT1_NAME, INGREDIENT1_QTY "
+ "[,INGREDIENT1_NAME, INGREDIENT1_QTY...] \n"
+ "Example: " + COMMAND_WORD
- + " name/chicken rice price/3.00 ingredient/rice qty/1 cup, ingredient/chicken qty/100g";
- Dish dish;
+ + " name/chicken rice price/3.00 ingredient/rice qty/200g, ingredient/chicken qty/100g";
+
+ private final Dish dish;
public AddDishCommand(Dish dish) {
this.dish = dish;
}
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index d2a2c37876..d282dd8ca0 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -134,7 +134,7 @@ private static Command prepareAdd(String arguments) {
try {
// Checks whether the overall pattern of add arguments is correct
if (!matcher.matches()) {
- return new IncorrectCommand("Error: Incorrect format for the add command.\n"
+ return new IncorrectCommand(Messages.INVALID_ADD_DISH_FORMAT_MESSAGE
+ AddDishCommand.MESSAGE_USAGE);
}
@@ -154,7 +154,7 @@ private static Command prepareAdd(String arguments) {
return new AddDishCommand(dish);
} catch (IllegalArgumentException e) {
- return new IncorrectCommand("Error: Incorrect format for the ingredients.\n"
+ return new IncorrectCommand(Messages.INVALID_ADD_DISH_FORMAT_MESSAGE
+ AddDishCommand.MESSAGE_USAGE);
}
}
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 7122b36dd2..bd5cbda57a 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -33,9 +33,7 @@ public class Messages {
public static final String MENU_TOP = "+-----------------------------------------+";
public static final String MENU_CORNER = "+--------------------------+--------------+";
public static final String MENU_TITLE = "| Dish Name | Price |";
-
public static final String ADD_DISH_MESSAGE = "You have added the following dish...";
-
-
+ public static final String INVALID_ADD_DISH_FORMAT_MESSAGE = "Error: Incorrect format for the add command.\n";
}
From d2c657d8b35474fa8ab79ecdaca5159baf2c2aac Mon Sep 17 00:00:00 2001
From: Dexter Hoon
Date: Mon, 23 Oct 2023 21:02:44 +0800
Subject: [PATCH 186/870] Change ingredientParsing function
---
src/main/java/seedu/cafectrl/parser/Parser.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index 5fa4a07ba5..b5a34b2fdf 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -144,10 +144,7 @@ private static Command prepareAdd(String arguments) {
checkNegativePrice(price);
- // Capture the list of ingredients
- ArrayList ingredients = new ArrayList<>();
-
- ingredientParsing(ingredientsListString, ingredients);
+ ArrayList ingredients = ingredientParsing(ingredientsListString);
Dish dish = new Dish(dishName, ingredients, price);
@@ -164,9 +161,10 @@ private static void checkNegativePrice(float price) throws IllegalArgumentExcept
}
}
- private static void ingredientParsing(String ingredientsListString, ArrayList ingredients)
+ private static ArrayList ingredientParsing(String ingredientsListString)
throws IllegalArgumentException {
String[] ingredientListInputText = {ingredientsListString};
+ ArrayList ingredients = new ArrayList<>();
//check if there is more than 1 ingredient
if (ingredientsListString.contains(INGREDIENT_DIVIDER_STRING)) {
@@ -189,6 +187,8 @@ private static void ingredientParsing(String ingredientsListString, ArrayList
Date: Mon, 23 Oct 2023 21:03:15 +0800
Subject: [PATCH 187/870] Add Javadoc comments
---
src/main/java/seedu/cafectrl/parser/Parser.java | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/cafectrl/parser/Parser.java b/src/main/java/seedu/cafectrl/parser/Parser.java
index b5a34b2fdf..a56f2ef848 100644
--- a/src/main/java/seedu/cafectrl/parser/Parser.java
+++ b/src/main/java/seedu/cafectrl/parser/Parser.java
@@ -126,6 +126,11 @@ private static Command prepareEditPriceCommand(Menu menu, String arguments) {
}
}
+ /**
+ * Parses the user input text into ingredients to form a Dish
that is added to the Menu
+ * @param arguments
+ * @return new AddDishCommand
+ */
private static Command prepareAdd(String arguments) {
final Pattern addArgumentPatter = Pattern.compile(ADD_ARGUMENT_STRING);
Matcher matcher = addArgumentPatter.matcher(arguments);
@@ -154,6 +159,7 @@ private static Command prepareAdd(String arguments) {
+ AddDishCommand.MESSAGE_USAGE);
}
}
+
/** to be removed once the new regex is implemented because new regex only allows positive prices*/
private static void checkNegativePrice(float price) throws IllegalArgumentException {
if (price < 0) {
@@ -161,6 +167,13 @@ private static void checkNegativePrice(float price) throws IllegalArgumentExcept
}
}
+ /**
+ * Parses the user's input text ingredients into Ingredient
objects that is added into
+ * list of ingredients for the Dish
object that is going to be added to the Menu
+ * @param ingredientsListString user's input string of ingredients
+ * @return Ingredient objects that consists of the dish
+ * @throws IllegalArgumentException if the input string of ingredients is in an incorrect format.
+ */
private static ArrayList ingredientParsing(String ingredientsListString)
throws IllegalArgumentException {
String[] ingredientListInputText = {ingredientsListString};
@@ -168,10 +181,11 @@ private static ArrayList ingredientParsing(String ingredientsListStr
//check if there is more than 1 ingredient
if (ingredientsListString.contains(INGREDIENT_DIVIDER_STRING)) {
- //split the ingredients into separate individual ingredients
+ //split the whole string of ingredients into separate individual ingredients
ingredientListInputText = ingredientsListString.split(INGREDIENT_DIVIDER_REGEX);
}
+ //Parsing each ingredient
for (String inputIngredientText: ingredientListInputText) {
final Pattern ingredientPattern = Pattern.compile(INGREDIENT_ARGUMENT_STRING);
Matcher ingredientMatcher = ingredientPattern.matcher(inputIngredientText);
From 2dae7a2dfb59ee73d09ed981ea3c94faf6345f85 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Mon, 23 Oct 2023 22:03:01 +0800
Subject: [PATCH 188/870] Improve code quality
Fixes #90, Fixes #91
---
src/main/java/seedu/cafectrl/data/Pantry.java | 1 -
src/main/java/seedu/cafectrl/data/dish/Ingredient.java | 2 +-
.../java/seedu/cafectrl/command/ListIngredientCommandTest.java | 2 +-
3 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java
index 80ed93f2f1..bb25026798 100644
--- a/src/main/java/seedu/cafectrl/data/Pantry.java
+++ b/src/main/java/seedu/cafectrl/data/Pantry.java
@@ -61,7 +61,6 @@ public Ingredient addIngredientToStock (String name, int qty, String unit) {
pantryStock.add(ingredient);
//TODO: Add file writer to write update pantry.txt
return ingredient;
-
}
/**
diff --git a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
index 392ba38f99..6509613fa0 100644
--- a/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
+++ b/src/main/java/seedu/cafectrl/data/dish/Ingredient.java
@@ -32,7 +32,7 @@ public void setQty(int qty) {
@Override
public String toString() {
- return name + " - " + qty;
+ return name + " - " + qty + unit;
}
}
diff --git a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
index 5cea050f9f..27b6e883c3 100644
--- a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
@@ -37,7 +37,7 @@ public void showToUser(String... message) {
listIngredientCommand.execute(menu, ui);
String expectedOutput = "Chicken Rice Ingredients: \n" +
- "Rice - 1 cup\n" +
+ "Rice - 1cup\n" +
"Chicken - 100g\n";
assertEquals(expectedOutput.trim().replaceAll("\\s+", " "),
From f9a255fb362187b5b41de91f2f9dea4d3985c04c Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Mon, 23 Oct 2023 22:28:13 +0800
Subject: [PATCH 189/870] Improve code quality
---
src/main/java/seedu/cafectrl/ui/Messages.java | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Messages.java b/src/main/java/seedu/cafectrl/ui/Messages.java
index 683cd91291..7748b54a9c 100644
--- a/src/main/java/seedu/cafectrl/ui/Messages.java
+++ b/src/main/java/seedu/cafectrl/ui/Messages.java
@@ -2,12 +2,9 @@
public class Messages {
- /**
- * Greeting messages
- */
+ /** Greeting messages */
public static final String LINE_STRING = "-----------------------------------------------------";
public static final String WELCOME_MESSAGE = "Hello! Welcome to CafeCTRL!";
-
public static final String GOODBYE_MESSAGE = "Goodbye <3 Have a great day ahead!";
/** Messages for edit price command */
@@ -23,12 +20,12 @@ public class Messages {
/** Messages for add dish command */
public static final String ADD_DISH_MESSAGE = "You have added the following dish...";
- public static final String VIEW_STOCK = "You have the following ingredients in pantry:";
public static final String INVALID_ADD_DISH_FORMAT_MESSAGE = "Error: Incorrect format for the add command.\n";
- /**
- * Messages for help command
- */
+ /** Messages for view stock command */
+ public static final String VIEW_STOCK = "You have the following ingredients in pantry:";
+
+ /** Messages for help command */
public static final String LIST_OF_COMMANDS = "These are all the commands I recognise: ";
public static final String INSTRUCTION_ON_COMMAND_FORMAT = "(- Words in UPPER_CASE are "
+ "the parameters to be supplied by the user.\n"
From f61f1d549bd4af23fa2aa533b60b6c10dd0d39c2 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Mon, 23 Oct 2023 22:46:46 +0800
Subject: [PATCH 190/870] Add method to write pantry list to storage
---
src/main/java/seedu/cafectrl/data/Pantry.java | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java
index bb25026798..cf6c074815 100644
--- a/src/main/java/seedu/cafectrl/data/Pantry.java
+++ b/src/main/java/seedu/cafectrl/data/Pantry.java
@@ -32,12 +32,19 @@ public ArrayList getPantryStock() {
*
* @return An ArrayList of Ingredient objects representing the pantry stock.
*/
- public ArrayList retrieveStockFromStorage () {
+ public ArrayList retrieveStockFromStorage() {
ArrayList pantryStock = new ArrayList<>();
//TODO: Add file reader to read from pantry.txt
return pantryStock;
}
+ /**
+ * Writes the pantry stock to storage, e.g., by write to a file (pantry.txt).
+ */
+ public void writeToPantryStorage() {
+ //TODO: Add file writer to write update pantry.txt
+ }
+
/**
* Adds or updates an ingredient in the pantry stock based on its name and quantity.
@@ -50,16 +57,16 @@ public ArrayList retrieveStockFromStorage () {
public Ingredient addIngredientToStock (String name, int qty, String unit) {
pantryStock = getPantryStock(); //get latest pantry stock from pantry.txt
int ingredientIndex = getIndexOfIngredient(name);
+ //TODO: Add error handling for invalid index
//if ingredient exists in pantry, add quantity of that ingredient
if (ingredientIndex != -1) {
- return addQty(qty, ingredientIndex);
+ return addIngredientQuantity(qty, ingredientIndex);
}
//else, add new ingredient to pantry
Ingredient ingredient = new Ingredient(name, qty, unit);
pantryStock.add(ingredient);
- //TODO: Add file writer to write update pantry.txt
return ingredient;
}
@@ -70,7 +77,7 @@ public Ingredient addIngredientToStock (String name, int qty, String unit) {
* @param ingredientIndex The index of the ingredient in the pantry stock (-1 if not found).
* @return The Ingredient object that was added or updated in the pantry stock.
*/
- private Ingredient addQty(int qty, int ingredientIndex) {
+ private Ingredient addIngredientQuantity(int qty, int ingredientIndex) {
Ingredient ingredient = pantryStock.get(ingredientIndex);
qty += ingredient.getQty(); //adds new qty to current qty
ingredient.setQty(qty);
From 57eb8502badae1d6fdaaec17f5c8bddc07e337f9 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Mon, 23 Oct 2023 22:46:58 +0800
Subject: [PATCH 191/870] Improve coding quality
---
src/main/java/seedu/cafectrl/ui/Ui.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index 17283783f9..82fc639fb4 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -82,14 +82,18 @@ public void showDeleteMessage(Dish selectedDish) {
showToUser("Okay! " + selectedDish.getName() + " is deleted! :)");
}
+ /**
+ * Shows ingredient to buy message to user
+ *
+ * @param ingredient Ingredient to be bought
+ */
public void showBuyIngredientMessage(Ingredient ingredient) {
String header = "Added to stock: \n";
String ingredientString = "Ingredient: " + ingredient.getName()
- + " Qty: " + ingredient.getQty();
+ + "\tQty: " + ingredient.getQty();
showToUser(header + ingredientString);
}
-
/**
* Shows messages(s) to the user
* @param message string(s) of messages to print
From c94591a0a0b63758478a837cdc66bbca828db743 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Mon, 23 Oct 2023 22:51:11 +0800
Subject: [PATCH 192/870] Improve code quality
---
.../java/seedu/cafectrl/command/AddDishCommandTest.java | 2 +-
.../seedu/cafectrl/command/ListIngredientCommandTest.java | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
index 7e78deb4ee..f98434a221 100644
--- a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
@@ -18,7 +18,7 @@ void execute_oneDishAdded_expectDishInMenu() {
Menu menu = new Menu(menuItems);
Ui ui = new Ui();
//creating a dish
- ingredients.add(new Ingredient("chicken",100, "g"));
+ ingredients.add(new Ingredient("chicken", 100, "g"));
Dish dish = new Dish("Chicken Rice", ingredients, (float) 1.00);
AddDishCommand addDishCommand = new AddDishCommand(dish);
diff --git a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
index 27b6e883c3..b4434ae3ef 100644
--- a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
@@ -36,9 +36,9 @@ public void showToUser(String... message) {
ListIngredientCommand listIngredientCommand = new ListIngredientCommand(indexToSelect);
listIngredientCommand.execute(menu, ui);
- String expectedOutput = "Chicken Rice Ingredients: \n" +
- "Rice - 1cup\n" +
- "Chicken - 100g\n";
+ String expectedOutput = "Chicken Rice Ingredients: \n"
+ + "Rice - 1cup\n"
+ + "Chicken - 100g\n";
assertEquals(expectedOutput.trim().replaceAll("\\s+", " "),
actualOutput.get(0).trim().replaceAll("\\s+", " "));
From 5c0fb17c294a54c982dfcc760a0f860c6617dfbd Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Mon, 23 Oct 2023 23:01:54 +0800
Subject: [PATCH 193/870] Instantiate pantry object at main and add pantry
parameter to execute methods
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 5 ++++-
src/main/java/seedu/cafectrl/command/AddDishCommand.java | 3 ++-
.../java/seedu/cafectrl/command/BuyIngredientCommand.java | 4 +---
src/main/java/seedu/cafectrl/command/Command.java | 3 ++-
src/main/java/seedu/cafectrl/command/DeleteDishCommand.java | 3 ++-
src/main/java/seedu/cafectrl/command/EditPriceCommand.java | 3 ++-
src/main/java/seedu/cafectrl/command/ExitCommand.java | 4 +++-
src/main/java/seedu/cafectrl/command/HelpCommand.java | 3 ++-
src/main/java/seedu/cafectrl/command/IncorrectCommand.java | 3 ++-
.../java/seedu/cafectrl/command/ListIngredientCommand.java | 3 ++-
src/main/java/seedu/cafectrl/command/ListMenuCommand.java | 3 ++-
.../java/seedu/cafectrl/command/ViewTotalStockCommand.java | 2 +-
12 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
index 5112fa3f95..5a1749d653 100644
--- a/src/main/java/seedu/cafectrl/CafeCtrl.java
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -2,6 +2,7 @@
import seedu.cafectrl.command.Command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.parser.Parser;
import seedu.cafectrl.ui.Ui;
@@ -13,6 +14,7 @@ public class CafeCtrl {
private final Ui ui;
private final Menu menu;
private Command command;
+ private Pantry pantry;
/**
* Private constructor for the CafeCtrl class, used for initializing the user interface and menu list.
@@ -20,6 +22,7 @@ public class CafeCtrl {
private CafeCtrl() {
ui = new Ui();
menu = new Menu();
+ pantry = new Pantry();
}
private void setup() {
@@ -38,7 +41,7 @@ private void run() {
try {
String fullUserInput = ui.receiveUserInput();
command = Parser.parseCommand(menu, fullUserInput);
- command.execute(menu, ui);
+ command.execute(menu, ui, pantry);
} catch (Exception e) {
ui.showToUser(e.getMessage());
} finally {
diff --git a/src/main/java/seedu/cafectrl/command/AddDishCommand.java b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
index 263e2a4dc3..2fd8519d28 100644
--- a/src/main/java/seedu/cafectrl/command/AddDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/AddDishCommand.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Ui;
@@ -21,7 +22,7 @@ public AddDishCommand(Dish dish) {
this.dish = dish;
}
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
menu.addDish(dish);
ui.printAddDishMessage(dish);
}
diff --git a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java
index d86d6ca3cf..8665fdbfe7 100644
--- a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java
+++ b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java
@@ -12,18 +12,16 @@ public class BuyIngredientCommand extends Command {
private String name;
private int qty;
private String unit;
- private Pantry pantry;
public BuyIngredientCommand(String name, int qty, String unit) {
this.name = name;
this.qty = qty;
this.unit = unit;
- pantry = new Pantry();
}
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
Ingredient ingredient = pantry.addIngredientToStock(name, qty, unit);
ui.showBuyIngredientMessage(ingredient);
}
diff --git a/src/main/java/seedu/cafectrl/command/Command.java b/src/main/java/seedu/cafectrl/command/Command.java
index f808b55dca..e6b4e01356 100644
--- a/src/main/java/seedu/cafectrl/command/Command.java
+++ b/src/main/java/seedu/cafectrl/command/Command.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.ui.Ui;
/**
@@ -26,7 +27,7 @@ public boolean isExit() {
/**
* Executes the command and returns the result.
*/
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
throw new UnsupportedOperationException("This method is to be implemented by child classes");
};
}
diff --git a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
index a42f9b1eff..6589bd672b 100644
--- a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
+++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
@@ -22,7 +23,7 @@ public DeleteDishCommand(int listIndex) {
}
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
try {
int dishIndexToBeDeleted = index - Ui.OFFSET_LIST_INDEX;
Dish selectedDish = menu.getMenuItemsList().get(dishIndexToBeDeleted);
diff --git a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
index 0c4b968ba2..fd691933af 100644
--- a/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
+++ b/src/main/java/seedu/cafectrl/command/EditPriceCommand.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Ui;
@@ -22,7 +23,7 @@ public EditPriceCommand(int menuID, float newPrice) {
* @param menu menu of the current session
* @param ui ui of the current session
*/
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
Dish dish = menu.getDish(this.menuID - Ui.OFFSET_LIST_INDEX);
dish.setPrice(this.newPrice);
diff --git a/src/main/java/seedu/cafectrl/command/ExitCommand.java b/src/main/java/seedu/cafectrl/command/ExitCommand.java
index 1ef0856578..d05c18cfb8 100644
--- a/src/main/java/seedu/cafectrl/command/ExitCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ExitCommand.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.ui.Ui;
public class ExitCommand extends Command {
@@ -18,8 +19,9 @@ public boolean isExit() {
}
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
ui.printLine();
ui.showGoodbye();
+ pantry.writeToPantryStorage();
}
}
diff --git a/src/main/java/seedu/cafectrl/command/HelpCommand.java b/src/main/java/seedu/cafectrl/command/HelpCommand.java
index 9f4b4e5532..a35c4b07fc 100644
--- a/src/main/java/seedu/cafectrl/command/HelpCommand.java
+++ b/src/main/java/seedu/cafectrl/command/HelpCommand.java
@@ -1,13 +1,14 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.ui.Ui;
public class HelpCommand extends Command {
public static final String COMMAND_WORD = "help";
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
ui.printLine();
ui.showHelp();
}
diff --git a/src/main/java/seedu/cafectrl/command/IncorrectCommand.java b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
index d9ba4f0fa9..98487df49c 100644
--- a/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
+++ b/src/main/java/seedu/cafectrl/command/IncorrectCommand.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.ui.Ui;
/**
@@ -14,7 +15,7 @@ public IncorrectCommand(String feedbackToUser) {
}
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
ui.showToUser(feedbackToUser);
}
}
diff --git a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
index e5c13ce31e..6cd7f89ba4 100644
--- a/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListIngredientCommand.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
@@ -20,7 +21,7 @@ public ListIngredientCommand(int listIndex) {
}
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
try {
Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX);
ui.printIngredients(selectedDish);
diff --git a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
index a1d482504b..9d06ea50cf 100644
--- a/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ListMenuCommand.java
@@ -1,6 +1,7 @@
package seedu.cafectrl.command;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
@@ -21,7 +22,7 @@ public class ListMenuCommand extends Command {
* @param ui Handles the interactions with user
*/
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
if (menu.getSize() == 0) {
printEmptyMenu(ui);
return;
diff --git a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
index cd615bbb41..3bab21372f 100644
--- a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
@@ -20,7 +20,7 @@ public ViewTotalStockCommand() {
}
@Override
- public void execute(Menu menu, Ui ui) {
+ public void execute(Menu menu, Ui ui, Pantry pantry) {
ui.showToUser(Messages.VIEW_STOCK);
pantryStock = pantry.getPantryStock();
From 7f63281f8d0d6607f26211dd1d6913febd008b32 Mon Sep 17 00:00:00 2001
From: ShaniceTang
Date: Mon, 23 Oct 2023 23:06:56 +0800
Subject: [PATCH 194/870] Update parameters of execute method in JUnit tests
---
.../seedu/cafectrl/command/AddDishCommandTest.java | 4 ++--
.../seedu/cafectrl/command/DeleteDishCommandTest.java | 5 +++--
.../seedu/cafectrl/command/EditPriceCommandTest.java | 3 ++-
.../java/seedu/cafectrl/command/HelpCommandTest.java | 3 ++-
.../cafectrl/command/ListIngredientCommandTest.java | 5 +++--
.../seedu/cafectrl/command/ListMenuCommandTest.java | 3 ++-
src/test/java/seedu/cafectrl/parser/ParserTest.java | 11 ++++++-----
7 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
index f98434a221..21e96dc0a8 100644
--- a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
@@ -2,6 +2,7 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
import seedu.cafectrl.ui.Ui;
@@ -16,14 +17,13 @@ void execute_oneDishAdded_expectDishInMenu() {
ArrayList ingredients = new ArrayList<>();
ArrayList menuItems = new ArrayList<>();
Menu menu = new Menu(menuItems);
- Ui ui = new Ui();
//creating a dish
ingredients.add(new Ingredient("chicken", 100, "g"));
Dish dish = new Dish("Chicken Rice", ingredients, (float) 1.00);
AddDishCommand addDishCommand = new AddDishCommand(dish);
- addDishCommand.execute(menu, ui);
+ addDishCommand.execute(menu, new Ui(), new Pantry());
assertEquals(1, menu.getMenuItemsList().size());
}
diff --git a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
index 2850bb814c..961309c3f5 100644
--- a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
@@ -2,6 +2,7 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Ui;
@@ -31,7 +32,7 @@ public void showToUser(String... message) {
int testIndex = 2;
DeleteDishCommand deleteDishCommand = new DeleteDishCommand(testIndex);
- deleteDishCommand.execute(menu, ui);
+ deleteDishCommand.execute(menu, ui, new Pantry());
int actualOutputIndex = 0;
String expectedOutput = "Okay! Chicken Curry is deleted! :)";
@@ -49,6 +50,6 @@ void execute_invalidInput_throwIndexOutOfBoundsException() {
int testIndex = 5;
DeleteDishCommand deleteDishCommand = new DeleteDishCommand(testIndex);
- assertThrows(IndexOutOfBoundsException.class, () -> deleteDishCommand.execute(menu, ui));
+ assertThrows(IndexOutOfBoundsException.class, () -> deleteDishCommand.execute(menu, ui, new Pantry()));
}
}
diff --git a/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
index f9061520cc..98e273e7e0 100644
--- a/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
@@ -2,6 +2,7 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
@@ -30,7 +31,7 @@ public void showToUser(String... message) {
int testDishIndex = 1;
float testNewPrice = 3;
Command editPriceCommand = new EditPriceCommand(testDishIndex, testNewPrice);
- editPriceCommand.execute(menu, ui);
+ editPriceCommand.execute(menu, ui, new Pantry());
int firstLine = 0;
int secondLine = 1;
diff --git a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
index 7cafb347b3..6cde480e4a 100644
--- a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
@@ -2,6 +2,7 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;
@@ -30,7 +31,7 @@ public void showToUserWithSpaceBetweenLines(String... message) {
};
HelpCommand helpCommand = new HelpCommand();
- helpCommand.execute(menu, ui);
+ helpCommand.execute(menu, ui, new Pantry());
int numOfLines = 8;
ArrayList expectedOutputs = new ArrayList<>();
diff --git a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
index b4434ae3ef..83742b1de7 100644
--- a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
@@ -2,6 +2,7 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
import seedu.cafectrl.ui.Ui;
@@ -34,7 +35,7 @@ public void showToUser(String... message) {
int indexToSelect = 1;
ListIngredientCommand listIngredientCommand = new ListIngredientCommand(indexToSelect);
- listIngredientCommand.execute(menu, ui);
+ listIngredientCommand.execute(menu, ui, new Pantry());
String expectedOutput = "Chicken Rice Ingredients: \n"
+ "Rice - 1cup\n"
@@ -58,7 +59,7 @@ public void execute_invalidIndex_returnsErrorMessage() {
assertThrows(IllegalArgumentException.class, () -> {
ListIngredientCommand listIngredientCommand = new ListIngredientCommand(invalidIndex);
- listIngredientCommand.execute(menu, ui);
+ listIngredientCommand.execute(menu, ui, new Pantry());
});
}
}
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index 7c3d228744..a4931f4d44 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -2,6 +2,7 @@
import org.junit.jupiter.api.Test;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.ui.Ui;
@@ -34,7 +35,7 @@ public void formatListMenu(String dishName, String dishPrice) {
};
Command listMenuCommand = new ListMenuCommand();
- listMenuCommand.execute(menu, ui);
+ listMenuCommand.execute(menu, ui, new Pantry());
String actualOutput = String.join(",", commandOutput);
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index effaae2cac..6f54a2dd60 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -7,6 +7,7 @@
import seedu.cafectrl.command.IncorrectCommand;
import seedu.cafectrl.command.ListIngredientCommand;
import seedu.cafectrl.data.Menu;
+import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
import seedu.cafectrl.ui.Messages;
@@ -159,7 +160,7 @@ public void showToUser(String... message) {
};
Command commandReturned = Parser.parseCommand(menu, testUserInput);
- commandReturned.execute(menu, ui);
+ commandReturned.execute(menu, ui, new Pantry());
assertEquals(Messages.UNKNOWN_COMMAND_MESSAGE, actualOutput.get(0));
}
@@ -179,7 +180,7 @@ public void showToUser(String... message) {
};
Command commandReturned = Parser.parseCommand(menu, testUserInput);
- commandReturned.execute(menu, ui);
+ commandReturned.execute(menu, ui, new Pantry());
assertEquals(Messages.MISSING_ARGUMENT_FOR_EDIT_PRICE, actualOutput.get(0));
}
@@ -199,7 +200,7 @@ public void showToUser(String... message) {
};
Command commandReturned = Parser.parseCommand(menu, testUserInput);
- commandReturned.execute(menu, ui);
+ commandReturned.execute(menu, ui, new Pantry());
assertEquals(Messages.INVALID_DISH_INDEX, actualOutput.get(0));
}
@@ -212,7 +213,7 @@ void parseCommand_validDishInputForAddDish_dishAddedToMenu() {
//Test for correct Command type returned
assertTrue(outputCommand instanceof AddDishCommand);
//Test for 1 Dish added to Menu
- outputCommand.execute(menu, ui);
+ outputCommand.execute(menu, ui, new Pantry());
assertEquals(1, menu.getSize());
//Test for correct parsing of dish arguments
Dish getOutputDish = menu.getDish(0);
@@ -231,7 +232,7 @@ void parseCommand_invalidDishInputForAddDish_noDishAddedToMenu() {
//Test for incorrect Command type returned
assertFalse(outputCommand instanceof AddDishCommand);
//Test for no dish added in menu
- outputCommand.execute(menu, ui);
+ outputCommand.execute(menu, ui, new Pantry());
assertEquals(0, menu.getSize());
}
}
From 88235e7b9833aeaf0080fb2678cb6b8bb3e925f8 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Tue, 24 Oct 2023 00:01:21 +0800
Subject: [PATCH 195/870] Refactor code to abstract print functions to UI
class.
Fixes #92, Fixes #93
---
src/main/java/seedu/cafectrl/data/Pantry.java | 64 +++++++------------
src/main/java/seedu/cafectrl/ui/Ui.java | 11 ++++
2 files changed, 33 insertions(+), 42 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java
index d8a587725a..28122da3b8 100644
--- a/src/main/java/seedu/cafectrl/data/Pantry.java
+++ b/src/main/java/seedu/cafectrl/data/Pantry.java
@@ -13,61 +13,42 @@ public class Pantry {
private ArrayList menuItems;
private Ui ui;
- public Pantry() {
- this.ui = new Ui();
+ public Pantry(Ui ui) {
+ this.ui = ui;
}
/**
* Checks the stock of ingredients and dish availability based on a given order.
*/
public void checkIngredientsStock(){
- //pass in dish when order function is completed
+ //the dish variable and dishIngredients array will be removed
+ // when order class is implemented as it will pass in dishIngredients
String dish = "Chicken Rice";
- decreaseIngredientsStock(dish);
+ ArrayList dishIngredients = retrieveIngredientsForDish(dish);
+ decreaseIngredientsStock(dishIngredients);
checkDishAvailability();
}
/**
* Decreases the stock of ingredients based on the given dish order.
*
- * @param dish The name of the dish being ordered.
+ * @param dishIngredients
*/
- public void decreaseIngredientsStock(String dish){
- ArrayList dishIngredients = retrieveIngredientsForDish(dish);
+ public void decreaseIngredientsStock(ArrayList dishIngredients){
pantryStock = retrieveStockFromStorage();
//for each ingredient that is used in the dish, update the stock of ingredient left.
for (Ingredient dishIngredient : dishIngredients) {
Ingredient usedIngredientFromStock = getIngredient(dishIngredient);
- String unit = extractUnit(dishIngredient.getQuantity());
- int stockQuantity = extractQuantity(usedIngredientFromStock);
- int usedQuantity = extractQuantity(dishIngredient);
+ int stockQuantity = usedIngredientFromStock.getQty();
+ int usedQuantity = dishIngredient.getQty();
+ int finalQuantity = stockQuantity-usedQuantity;
- usedIngredientFromStock.setQuantity(String.valueOf(stockQuantity-usedQuantity)+unit);
+ usedIngredientFromStock.setQuantity(String.valueOf(finalQuantity)+dishIngredient.getUnit());
}
//TODO: store pantryStock to storage
}
- /**
- * Extracts the quantity from the given ingredient quantity string.
- *
- * @param ingredient The ingredient from which quantity is extracted.
- * @return The extracted quantity as an integer.
- */
- private static int extractQuantity(Ingredient ingredient) {
- return Integer.parseInt(ingredient.getQuantity()
- .replaceAll("[^0-9]", ""));
- }
-
- /**
- * Extracts the unit from the given quantity string.
- *
- * @param qty The quantity string.
- * @return The extracted unit string.
- */
- public String extractUnit(String qty) {
- return qty.replaceAll("[0-9]", "");}
-
/**
* Retrieves the ingredient used in the ordered dish from pantryStock.
*
@@ -86,11 +67,9 @@ private Ingredient getIngredient(Ingredient dishIngredient) {
*/
public void checkDishAvailability(){
for (Dish dish : menuItems) {
- ui.printLine();
ui.showToUser("Dish: " + dish.getName());
int numberOfDishes = checkIngredientAvailability(dish);
- ui.showToUser("Available Dishes: " + numberOfDishes);
- ui.printLine();
+ ui.showDishAvailability(numberOfDishes);
}
}
@@ -101,6 +80,8 @@ public void checkDishAvailability(){
*/
public int checkIngredientAvailability(Dish dish) {
int maxNumofDish = Integer.MAX_VALUE;
+ //This function will be replaced by the function used
+ //to retrieve dishIngredients when order class is implemented
ArrayList dishIngredients = retrieveIngredientsForDish(dish.getName());
for (Ingredient dishIngredient : dishIngredients) {
@@ -127,8 +108,8 @@ private int calculateNumOfDish(Ingredient dishIngredient) {
return 0;
}
- int currentQuantity = extractQuantity(usedIngredientFromStock);
- int usedQuantity = extractQuantity(dishIngredient);
+ int currentQuantity = usedIngredientFromStock.getQty();
+ int usedQuantity = dishIngredient.getQty();
return currentQuantity / usedQuantity;
}
@@ -138,15 +119,13 @@ private int calculateNumOfDish(Ingredient dishIngredient) {
* @param dishIngredient The ingredient for which restocking is needed.
*/
private void handleRestock(Ingredient dishIngredient) {
- String unit = extractUnit(dishIngredient.getQuantity());
String dishIngredientName = dishIngredient.getName();
-
- ui.showToUser("Please Restock: " + dishIngredientName);
Ingredient stockIngredient = getIngredient(dishIngredient);
- int currentQuantity = (stockIngredient == null) ? 0 : extractQuantity(stockIngredient);
- ui.showToUser("Current " + dishIngredientName + ": " + currentQuantity + unit);
- ui.showToUser("Needed " + dishIngredientName + ": " + extractQuantity(dishIngredient) + unit);
+ int currentQuantity = (stockIngredient == null) ? 0 : stockIngredient.getQty();
+ String unit = dishIngredient.getUnit();
+ String neededIngredient = dishIngredient.toString();
+ ui.showNeededRestock(dishIngredientName, currentQuantity, unit, neededIngredient);
}
@@ -157,6 +136,7 @@ private void handleRestock(Ingredient dishIngredient) {
* @return The list of ingredients for the ordered dish.
*/
public ArrayList retrieveIngredientsForDish(String orderedDish){
+ //function will be removed once order class is implemented
ArrayList menuItems = dummyData();
ArrayList dishIngredients = new ArrayList<>();
diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java
index ceb50e1a33..e8c2b4a08a 100644
--- a/src/main/java/seedu/cafectrl/ui/Ui.java
+++ b/src/main/java/seedu/cafectrl/ui/Ui.java
@@ -123,4 +123,15 @@ public void showToUserWithSpaceBetweenLines(String... message) {
System.out.println(m + "\n");
}
}
+
+ public void showDishAvailability(int numberOfDishes){
+ showToUser("Available Dishes: " + numberOfDishes);
+ printLine();
+ }
+
+ public void showNeededRestock(String ingredientName, int currentQuantity, String unit, String neededIngredient){
+ showToUser("Please Restock: " + ingredientName
+ , "Current " + ingredientName + ": " + currentQuantity + unit
+ , "Needed " + ingredientName + ": " + neededIngredient);
+ }
}
From b4d466fdd3ba96e2124e5e5c3bcaca1d675002a4 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Tue, 24 Oct 2023 00:12:41 +0800
Subject: [PATCH 196/870] Improve code quality by refactoring methods.
Fixes #92, Fixes #93
---
src/main/java/seedu/cafectrl/data/Pantry.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/data/Pantry.java b/src/main/java/seedu/cafectrl/data/Pantry.java
index 28122da3b8..069509f6f2 100644
--- a/src/main/java/seedu/cafectrl/data/Pantry.java
+++ b/src/main/java/seedu/cafectrl/data/Pantry.java
@@ -26,13 +26,13 @@ public void checkIngredientsStock(){
String dish = "Chicken Rice";
ArrayList dishIngredients = retrieveIngredientsForDish(dish);
decreaseIngredientsStock(dishIngredients);
- checkDishAvailability();
+ calculateDishAvailability();
}
/**
* Decreases the stock of ingredients based on the given dish order.
*
- * @param dishIngredients
+ * @param dishIngredients Array of ingredients used to make the dish order.
*/
public void decreaseIngredientsStock(ArrayList dishIngredients){
pantryStock = retrieveStockFromStorage();
@@ -65,27 +65,27 @@ private Ingredient getIngredient(Ingredient dishIngredient) {
/**
* Checks the availability of dishes based on ingredient stock.
*/
- public void checkDishAvailability(){
+ public void calculateDishAvailability(){
for (Dish dish : menuItems) {
ui.showToUser("Dish: " + dish.getName());
- int numberOfDishes = checkIngredientAvailability(dish);
+ int numberOfDishes = calculateMaxDishes(dish);
ui.showDishAvailability(numberOfDishes);
}
}
/**
- * Checks the availability of ingredients in the pantry for a given dish order.
+ * Calculates the number of dishes that can be prepared with the available ingredients.
*
* @param dish The dish being ordered.
*/
- public int checkIngredientAvailability(Dish dish) {
+ public int calculateMaxDishes(Dish dish) {
int maxNumofDish = Integer.MAX_VALUE;
//This function will be replaced by the function used
//to retrieve dishIngredients when order class is implemented
ArrayList dishIngredients = retrieveIngredientsForDish(dish.getName());
for (Ingredient dishIngredient : dishIngredients) {
- int numOfDish = calculateNumOfDish(dishIngredient);
+ int numOfDish = calculateMaxDishForEachIngredient(dishIngredient);
maxNumofDish = Math.min(numOfDish, maxNumofDish);
if (numOfDish == 0) {
@@ -97,12 +97,12 @@ public int checkIngredientAvailability(Dish dish) {
}
/**
- * Calculates the number of dishes that can be prepared with the available ingredients.
+ * Calculates the number of dishes that can be prepared with the provided ingredients.
*
* @param dishIngredient The ingredient used in the ordered dish.
* @return The number of dishes that can be prepared.
*/
- private int calculateNumOfDish(Ingredient dishIngredient) {
+ private int calculateMaxDishForEachIngredient(Ingredient dishIngredient) {
Ingredient usedIngredientFromStock = getIngredient(dishIngredient);
if (usedIngredientFromStock == null) {
return 0;
From 21b07cd22ff5826632905428a7efd3b451deac44 Mon Sep 17 00:00:00 2001
From: NaychiMin
Date: Tue, 24 Oct 2023 00:41:56 +0800
Subject: [PATCH 197/870] Edit existing constructor parameter of Pantry class.
Fixes #92, Fixes #93
---
src/main/java/seedu/cafectrl/CafeCtrl.java | 2 +-
.../seedu/cafectrl/command/ViewTotalStockCommand.java | 2 +-
.../seedu/cafectrl/command/AddDishCommandTest.java | 3 ++-
.../seedu/cafectrl/command/DeleteDishCommandTest.java | 4 ++--
.../seedu/cafectrl/command/EditPriceCommandTest.java | 2 +-
.../java/seedu/cafectrl/command/HelpCommandTest.java | 2 +-
.../cafectrl/command/ListIngredientCommandTest.java | 4 ++--
.../seedu/cafectrl/command/ListMenuCommandTest.java | 2 +-
src/test/java/seedu/cafectrl/parser/ParserTest.java | 10 +++++-----
9 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/main/java/seedu/cafectrl/CafeCtrl.java b/src/main/java/seedu/cafectrl/CafeCtrl.java
index 5a1749d653..ba2b471ded 100644
--- a/src/main/java/seedu/cafectrl/CafeCtrl.java
+++ b/src/main/java/seedu/cafectrl/CafeCtrl.java
@@ -22,7 +22,7 @@ public class CafeCtrl {
private CafeCtrl() {
ui = new Ui();
menu = new Menu();
- pantry = new Pantry();
+ pantry = new Pantry(ui);
}
private void setup() {
diff --git a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
index 3bab21372f..9c236ffac0 100644
--- a/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
+++ b/src/main/java/seedu/cafectrl/command/ViewTotalStockCommand.java
@@ -16,7 +16,7 @@ public class ViewTotalStockCommand extends Command {
private Pantry pantry;
public ViewTotalStockCommand() {
- this.pantry = new Pantry();
+ this.pantry = new Pantry(new Ui());
}
@Override
diff --git a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
index 21e96dc0a8..f2c44630dc 100644
--- a/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/AddDishCommandTest.java
@@ -23,7 +23,8 @@ void execute_oneDishAdded_expectDishInMenu() {
AddDishCommand addDishCommand = new AddDishCommand(dish);
- addDishCommand.execute(menu, new Ui(), new Pantry());
+ Ui ui = new Ui();
+ addDishCommand.execute(menu, ui, new Pantry(ui));
assertEquals(1, menu.getMenuItemsList().size());
}
diff --git a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
index 961309c3f5..2968a9cc2a 100644
--- a/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/DeleteDishCommandTest.java
@@ -32,7 +32,7 @@ public void showToUser(String... message) {
int testIndex = 2;
DeleteDishCommand deleteDishCommand = new DeleteDishCommand(testIndex);
- deleteDishCommand.execute(menu, ui, new Pantry());
+ deleteDishCommand.execute(menu, ui, new Pantry(ui));
int actualOutputIndex = 0;
String expectedOutput = "Okay! Chicken Curry is deleted! :)";
@@ -50,6 +50,6 @@ void execute_invalidInput_throwIndexOutOfBoundsException() {
int testIndex = 5;
DeleteDishCommand deleteDishCommand = new DeleteDishCommand(testIndex);
- assertThrows(IndexOutOfBoundsException.class, () -> deleteDishCommand.execute(menu, ui, new Pantry()));
+ assertThrows(IndexOutOfBoundsException.class, () -> deleteDishCommand.execute(menu, ui, new Pantry(ui)));
}
}
diff --git a/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
index 98e273e7e0..b3929b4cf0 100644
--- a/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/EditPriceCommandTest.java
@@ -31,7 +31,7 @@ public void showToUser(String... message) {
int testDishIndex = 1;
float testNewPrice = 3;
Command editPriceCommand = new EditPriceCommand(testDishIndex, testNewPrice);
- editPriceCommand.execute(menu, ui, new Pantry());
+ editPriceCommand.execute(menu, ui, new Pantry(ui));
int firstLine = 0;
int secondLine = 1;
diff --git a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
index 6cde480e4a..309a2c6edc 100644
--- a/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/HelpCommandTest.java
@@ -31,7 +31,7 @@ public void showToUserWithSpaceBetweenLines(String... message) {
};
HelpCommand helpCommand = new HelpCommand();
- helpCommand.execute(menu, ui, new Pantry());
+ helpCommand.execute(menu, ui, new Pantry(ui));
int numOfLines = 8;
ArrayList expectedOutputs = new ArrayList<>();
diff --git a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
index 83742b1de7..a561499042 100644
--- a/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListIngredientCommandTest.java
@@ -35,7 +35,7 @@ public void showToUser(String... message) {
int indexToSelect = 1;
ListIngredientCommand listIngredientCommand = new ListIngredientCommand(indexToSelect);
- listIngredientCommand.execute(menu, ui, new Pantry());
+ listIngredientCommand.execute(menu, ui, new Pantry(ui));
String expectedOutput = "Chicken Rice Ingredients: \n"
+ "Rice - 1cup\n"
@@ -59,7 +59,7 @@ public void execute_invalidIndex_returnsErrorMessage() {
assertThrows(IllegalArgumentException.class, () -> {
ListIngredientCommand listIngredientCommand = new ListIngredientCommand(invalidIndex);
- listIngredientCommand.execute(menu, ui, new Pantry());
+ listIngredientCommand.execute(menu, ui, new Pantry(ui));
});
}
}
diff --git a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
index a4931f4d44..445490e5ca 100644
--- a/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
+++ b/src/test/java/seedu/cafectrl/command/ListMenuCommandTest.java
@@ -35,7 +35,7 @@ public void formatListMenu(String dishName, String dishPrice) {
};
Command listMenuCommand = new ListMenuCommand();
- listMenuCommand.execute(menu, ui, new Pantry());
+ listMenuCommand.execute(menu, ui, new Pantry(ui));
String actualOutput = String.join(",", commandOutput);
diff --git a/src/test/java/seedu/cafectrl/parser/ParserTest.java b/src/test/java/seedu/cafectrl/parser/ParserTest.java
index 6f54a2dd60..4f019eff20 100644
--- a/src/test/java/seedu/cafectrl/parser/ParserTest.java
+++ b/src/test/java/seedu/cafectrl/parser/ParserTest.java
@@ -160,7 +160,7 @@ public void showToUser(String... message) {
};
Command commandReturned = Parser.parseCommand(menu, testUserInput);
- commandReturned.execute(menu, ui, new Pantry());
+ commandReturned.execute(menu, ui, new Pantry(ui));
assertEquals(Messages.UNKNOWN_COMMAND_MESSAGE, actualOutput.get(0));
}
@@ -180,7 +180,7 @@ public void showToUser(String... message) {
};
Command commandReturned = Parser.parseCommand(menu, testUserInput);
- commandReturned.execute(menu, ui, new Pantry());
+ commandReturned.execute(menu, ui, new Pantry(ui));
assertEquals(Messages.MISSING_ARGUMENT_FOR_EDIT_PRICE, actualOutput.get(0));
}
@@ -200,7 +200,7 @@ public void showToUser(String... message) {
};
Command commandReturned = Parser.parseCommand(menu, testUserInput);
- commandReturned.execute(menu, ui, new Pantry());
+ commandReturned.execute(menu, ui, new Pantry(ui));
assertEquals(Messages.INVALID_DISH_INDEX, actualOutput.get(0));
}
@@ -213,7 +213,7 @@ void parseCommand_validDishInputForAddDish_dishAddedToMenu() {
//Test for correct Command type returned
assertTrue(outputCommand instanceof AddDishCommand);
//Test for 1 Dish added to Menu
- outputCommand.execute(menu, ui, new Pantry());
+ outputCommand.execute(menu, ui, new Pantry(ui));
assertEquals(1, menu.getSize());
//Test for correct parsing of dish arguments
Dish getOutputDish = menu.getDish(0);
@@ -232,7 +232,7 @@ void parseCommand_invalidDishInputForAddDish_noDishAddedToMenu() {
//Test for incorrect Command type returned
assertFalse(outputCommand instanceof AddDishCommand);
//Test for no dish added in menu
- outputCommand.execute(menu, ui, new Pantry());
+ outputCommand.execute(menu, ui, new Pantry(ui));
assertEquals(0, menu.getSize());
}
}
From bfa0891e46c52dcfb3c301d159915bc0d5fcfaf7 Mon Sep 17 00:00:00 2001
From: Cazh1