From 074f8ce7c7d9ec97ac66998608e1b6b8227061a9 Mon Sep 17 00:00:00 2001
From: liuziyang <3189362094@qq.com>
Date: Fri, 10 Mar 2023 15:04:37 +0800
Subject: [PATCH 1/6] remove DUKEUI
---
src/main/java/seedu/duke/DukeUI.java | 30 ----------------------------
1 file changed, 30 deletions(-)
delete mode 100644 src/main/java/seedu/duke/DukeUI.java
diff --git a/src/main/java/seedu/duke/DukeUI.java b/src/main/java/seedu/duke/DukeUI.java
deleted file mode 100644
index 7f77fc133f..0000000000
--- a/src/main/java/seedu/duke/DukeUI.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package seedu.duke;
-
-import java.util.Scanner;
-
-public class DukeUI {
- private static final String LINE = "____________________________________________________________";
- private static final String DUKE_LOGO = "Hello from\n" +
- " ____ _ \n"
- + "| _ \\ _ _| | _____ \n"
- + "| | | | | | | |/ / _ \\\n"
- + "| |_| | |_| | < __/\n"
- + "|____/ \\__,_|_|\\_\\___|\n";
- public Scanner in;
-
- public DukeUI() {
- in = new Scanner(System.in);
- }
- public String readCommand() {
- return in.nextLine();
- }
- public void printDukeLogo() {
- System.out.println(DUKE_LOGO);
- }
- public void printGreeting(){
- printDukeLogo();
- }
- public void printLine(){
- System.out.println(LINE);
- }
-}
From c4405c384fd7a148ecaec68f035e48faa8bcac15 Mon Sep 17 00:00:00 2001
From: liuziyang <3189362094@qq.com>
Date: Wed, 15 Mar 2023 15:31:35 +0800
Subject: [PATCH 2/6] fixed bug in Scanner
---
data/recipeList.txt | 0
docs/team/limhongyao.md | 4 +-
docs/team/liuziyang.md | 5 +-
src/main/java/seedu/duke/Duke.java | 22 ++--
src/main/java/seedu/duke/command/Command.java | 30 ++---
.../java/seedu/duke/command/CommandType.java | 6 +-
src/main/java/seedu/duke/parser/Parser.java | 3 +
.../java/seedu/duke/recipe/RecipeList.java | 4 +
src/main/java/seedu/duke/ui/StringLib.java | 8 +-
.../java/seedu/duke/ui/{Ui.java => UI.java} | 67 +++++-------
text-ui-test/EXPECTED.TXT | 103 +++++++++++++++++-
text-ui-test/input.txt | 14 +++
12 files changed, 192 insertions(+), 74 deletions(-)
create mode 100644 data/recipeList.txt
rename src/main/java/seedu/duke/ui/{Ui.java => UI.java} (58%)
diff --git a/data/recipeList.txt b/data/recipeList.txt
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/docs/team/limhongyao.md b/docs/team/limhongyao.md
index ab75b391b8..6902d885b8 100644
--- a/docs/team/limhongyao.md
+++ b/docs/team/limhongyao.md
@@ -1,6 +1,6 @@
-# John Doe - Project Portfolio Page
+# Lim Hong Yao - Project Portfolio Page
## Overview
-
+
### Summary of Contributions
diff --git a/docs/team/liuziyang.md b/docs/team/liuziyang.md
index ab75b391b8..2ac27f26a5 100644
--- a/docs/team/liuziyang.md
+++ b/docs/team/liuziyang.md
@@ -1,6 +1,7 @@
-# John Doe - Project Portfolio Page
+# Liu Ziyang - Project Portfolio Page
## Overview
-
+Responsible for all items in the User Guide.
### Summary of Contributions
+
diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java
index 01ea2a609a..e9ce1dc0f5 100644
--- a/src/main/java/seedu/duke/Duke.java
+++ b/src/main/java/seedu/duke/Duke.java
@@ -4,7 +4,7 @@
import seedu.duke.parser.Parser;
import seedu.duke.recipe.RecipeList;
import seedu.duke.storage.Storage;
-import seedu.duke.ui.Ui;
+import seedu.duke.ui.UI;
/**
* Represents the Recipe Manager programme. A Duke
object corresponds to
@@ -13,7 +13,7 @@
public class Duke {
private final RecipeList recipes;
-
+ private final UI ui = new UI();
/**
* Class constructor specifying filePath for saving data.
*
@@ -24,10 +24,10 @@ public Duke(String filePath) {
try {
Storage.createSavedFile();
} catch (Exception e) {
- Ui.showLoadingErrorMessage(e);
+ ui.showLoadingErrorMessage(e);
} finally {
recipes = new RecipeList();
- Ui.showLine();
+ ui.showLine();
}
}
@@ -36,20 +36,20 @@ public Duke(String filePath) {
* it is terminated by the user.
*/
public void run() {
- Ui.showWelcome();
- Ui.showLine();
+ ui.showWelcome();
+ ui.showLine();
boolean isExit = false;
while (!isExit) {
try {
- String fullCommand = Ui.readCommand();
- Ui.showLine();
+ String fullCommand = ui.readCommand();
+ ui.showLine();
Command c = Parser.parseCommands(fullCommand);
- c.execute(recipes);
+ c.execute(recipes,ui);
isExit = c.isExit();
} catch (Exception e) {
- Ui.showDudeMainError(e);
+ ui.showDudeMainError(e);
} finally {
- Ui.showLine();
+ ui.showLine();
}
}
}
diff --git a/src/main/java/seedu/duke/command/Command.java b/src/main/java/seedu/duke/command/Command.java
index be2dbb8f38..800019b3e6 100644
--- a/src/main/java/seedu/duke/command/Command.java
+++ b/src/main/java/seedu/duke/command/Command.java
@@ -6,7 +6,7 @@
import seedu.duke.recipe.IngredientList;
import seedu.duke.recipe.Recipe;
import seedu.duke.recipe.RecipeList;
-import seedu.duke.ui.Ui;
+import seedu.duke.ui.UI;
import java.util.ArrayList;
@@ -48,13 +48,13 @@ public boolean isExit() {
*
* @param recipeList the current list of recipes to be modified or used.
*/
- public void execute(RecipeList recipeList) {
+ public void execute(RecipeList recipeList, UI ui) {
int recipeListIndex;
switch (type) {
case LIST:
- Ui.showRecipeList(recipeList.getRecipeList());
+ ui.showRecipeList(recipeList.getRecipeList());
break;
case ADD:
try {
@@ -67,9 +67,9 @@ public void execute(RecipeList recipeList) {
String recipeTag = parsed.get(2);
ArrayList recipeSteps = new ArrayList<>();
recipeList.addNewRecipe(new Recipe(recipeName, recipeTag, ingredientLists, recipeSteps));
- Ui.showRecipeAdded(recipeList.getNewestRecipe(), recipeList.getCurrRecipeNumber());
+ ui.showRecipeAdded(recipeList.getNewestRecipe(), recipeList.getCurrRecipeNumber());
} catch (Exception e) {
- Ui.showAddingRecipeErrorMessage(e);
+ ui.showAddingRecipeErrorMessage(e);
}
break;
case DELETE:
@@ -79,10 +79,10 @@ public void execute(RecipeList recipeList) {
}
recipeListIndex = Integer.parseInt(fullDescription);
Recipe recipeToBeDeleted = recipeList.getRecipeFromList(recipeListIndex);
- Ui.showRecipeDeleted(recipeToBeDeleted, recipeList.getCurrRecipeNumber() - 1);
+ ui.showRecipeDeleted(recipeToBeDeleted, recipeList.getCurrRecipeNumber() - 1);
recipeList.removeRecipe(recipeListIndex);
} catch (Exception e) {
- Ui.showDeletingTaskErrorMessage(e, type);
+ ui.showDeletingTaskErrorMessage(e, type);
}
break;
case FIND:
@@ -97,22 +97,26 @@ public void execute(RecipeList recipeList) {
findRecipeResults.add(recipe);
}
}
- Ui.showFindResults(findRecipeResults, keywords);
+ ui.showFindResults(findRecipeResults, keywords);
} catch (Exception e) {
- Ui.showFindingTaskErrorMessage(e);
+ ui.showFindingTaskErrorMessage(e);
}
break;
+ case CLEAR:
+ recipeList.clearRecipeList();
+ ui.showRecipeListCleared();
+ break;
case HELP:
- Ui.showHelp();
+ ui.showHelp();
break;
case EXIT:
- Ui.showExit();
+ ui.showExit();
break;
case UNKNOWN:
- Ui.showUnrecognizableErrorMessage();
+ ui.showUnrecognizableErrorMessage();
break;
default:
- Ui.showUnrecognizableCommandErrorMessage();
+ ui.showUnrecognizableCommandErrorMessage();
}
}
}
diff --git a/src/main/java/seedu/duke/command/CommandType.java b/src/main/java/seedu/duke/command/CommandType.java
index ba6f448008..4c01e4e122 100644
--- a/src/main/java/seedu/duke/command/CommandType.java
+++ b/src/main/java/seedu/duke/command/CommandType.java
@@ -38,7 +38,11 @@ public enum CommandType {
*/
HELP,
/**
- * Terminates the programme and exit with saving.
+ * Clear the current recipe list.
+ */
+ CLEAR,
+ /**
+ * Terminates the programme and exit without saving.
*/
EXIT,
/**
diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java
index 21c6ea3d26..406dc5f0e8 100644
--- a/src/main/java/seedu/duke/parser/Parser.java
+++ b/src/main/java/seedu/duke/parser/Parser.java
@@ -54,6 +54,9 @@ public static Command parseCommands(String line) {
case "find":
type = CommandType.FIND;
break;
+ case "clear":
+ type = CommandType.CLEAR;
+ break;
case "exit":
type = CommandType.EXIT;
break;
diff --git a/src/main/java/seedu/duke/recipe/RecipeList.java b/src/main/java/seedu/duke/recipe/RecipeList.java
index 0a237dae75..f5074c8726 100644
--- a/src/main/java/seedu/duke/recipe/RecipeList.java
+++ b/src/main/java/seedu/duke/recipe/RecipeList.java
@@ -46,4 +46,8 @@ public void removeRecipe(int index) throws RecipeListEmptyError {
recipeList.remove(index-1);
currRecipeNumber--;
}
+ public void clearRecipeList() {
+ recipeList.clear();
+ currRecipeNumber = 0;
+ }
}
diff --git a/src/main/java/seedu/duke/ui/StringLib.java b/src/main/java/seedu/duke/ui/StringLib.java
index 6aa6796d6b..fb6387769f 100644
--- a/src/main/java/seedu/duke/ui/StringLib.java
+++ b/src/main/java/seedu/duke/ui/StringLib.java
@@ -10,7 +10,7 @@ public interface StringLib {
+ " \\_/\\__,_|___/\\__\\___| \\___/|_| \\_| |_/\\___/|_| |_| |_| |___/ | | \\_/ \\___/\\_| |_/| |"
+ "\n"
+ " \\_\\ /_/\n";
- String WELCOME_MESSAGE = "\nHELLLOO there! I am\n "
+ String WELCOME_MESSAGE = "\nHELLO there! I am\n "
+ LOGO + '\n'
+ "Your personal recipes assistant!\n"
+ "What can I do for you today?\n\n"
@@ -100,7 +100,11 @@ public interface StringLib {
+ "\nException occurred: ";
String FILE_LOADING_DEFAULT_ERROR = "\nError in loading file!"
+ "\nException occurred: ";
-
String LINE = "__________________________________________________________";
+ String ADD_COMMAND_FORMAT = "\"Format: \\\"add n/"
+ + "i/ \"\n"
+ + "\"t/\\\"\\n\"\n"
+ + "\"Example use : \\\"add n/Hotpot i/Beef, Potatoes, Carrots t/Chinese\\\" \\n \\n\"";
+ String RECIPE_CLEARED_MESSAGE = "\nAll recipes have been cleared!";
}
diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/UI.java
similarity index 58%
rename from src/main/java/seedu/duke/ui/Ui.java
rename to src/main/java/seedu/duke/ui/UI.java
index 241a98837c..a985c0203d 100644
--- a/src/main/java/seedu/duke/ui/Ui.java
+++ b/src/main/java/seedu/duke/ui/UI.java
@@ -6,43 +6,23 @@
import seedu.duke.exceptions.RecipeListEmptyError;
import seedu.duke.recipe.Recipe;
-import static seedu.duke.ui.StringLib.CREATING_NEW_FILE_AND_DIRECTORY;
-import static seedu.duke.ui.StringLib.DUDE_MAIN_ERROR;
-import static seedu.duke.ui.StringLib.EMPTY_LIST_MESSAGE;
-import static seedu.duke.ui.StringLib.EXIT_MESSAGE;
-import static seedu.duke.ui.StringLib.FILE_IO_ERROR;
-import static seedu.duke.ui.StringLib.FILE_LOADING_DEFAULT_ERROR;
-import static seedu.duke.ui.StringLib.FILE_NOT_FOUND_ERROR;
-import static seedu.duke.ui.StringLib.FILE_PARSE_READING_ERROR;
-import static seedu.duke.ui.StringLib.FIND_LIST_MESSAGE;
-import static seedu.duke.ui.StringLib.HELP;
-import static seedu.duke.ui.StringLib.LINE;
-import static seedu.duke.ui.StringLib.MISSING_DESCRIPTION_ERROR;
-import static seedu.duke.ui.StringLib.MISSING_INPUTS_ERROR;
-import static seedu.duke.ui.StringLib.NO_MATCHING_FIND_RESULTS_MESSAGE;
-import static seedu.duke.ui.StringLib.PARSING_STRING_ERROR;
-import static seedu.duke.ui.StringLib.PREFIX_EMPTY_LIMIT_LIST_ERROR;
-import static seedu.duke.ui.StringLib.RECIPE_ADDING_DEFAULT_ERROR;
-import static seedu.duke.ui.StringLib.RECIPE_DELETING_DEFAULT_ERROR;
-import static seedu.duke.ui.StringLib.RECIPE_FINDING_DEFAULT_ERROR;
-import static seedu.duke.ui.StringLib.SUFFIX_EMPTY_LIMIT_LIST_ERROR;
-import static seedu.duke.ui.StringLib.UNRECOGNIZABLE_COMMAND_ERROR;
-import static seedu.duke.ui.StringLib.UNRECOGNIZABLE_ERROR;
-import static seedu.duke.ui.StringLib.WELCOME_MESSAGE;
-
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
+import static seedu.duke.ui.StringLib.*;
-public class Ui {
- public static String readCommand() {
- Scanner in = new Scanner(System.in);
+public class UI {
+ private static Scanner in;
+ public UI() {
+ in = new Scanner(System.in);
+ }
+ public String readCommand() {
return in.nextLine();
}
- public static void showFindResults(ArrayList list, String keywords) {
+ public void showFindResults(ArrayList list, String keywords) {
if (list.size() == 0) {
System.out.println(NO_MATCHING_FIND_RESULTS_MESSAGE + keywords + '\n');
return;
@@ -55,7 +35,7 @@ public static void showFindResults(ArrayList list, String keywords) {
}
System.out.println();
}
- public static void showRecipeList(ArrayList list) {
+ public void showRecipeList(ArrayList list) {
if (list.size() == 0) {
System.out.println(EMPTY_LIST_MESSAGE);
return;
@@ -68,43 +48,46 @@ public static void showRecipeList(ArrayList list) {
}
System.out.println();
}
- public static void showRecipeAdded(Recipe recipe, int recipeListSize) {
+ public void showRecipeAdded(Recipe recipe, int recipeListSize) {
System.out.println('\n' + "Got it. I've added this recipe:");
System.out.println(" " + recipe.toString());
System.out.println("Now you have " + recipeListSize + " recipes in the list." + '\n');
}
- public static void showRecipeDeleted(Recipe recipe, int recipeListSize) {
+ public void showRecipeDeleted(Recipe recipe, int recipeListSize) {
System.out.println('\n' + "Noted. I've removed this recipe:");
System.out.println(" " + recipe.toString());
System.out.println("Now you have " + recipeListSize + " recipes in the list." + '\n');
}
- public static void showWelcome() {
+ public void showRecipeListCleared() {
+ System.out.println(RECIPE_CLEARED_MESSAGE);
+ }
+ public void showWelcome() {
System.out.println(WELCOME_MESSAGE);
}
- public static void showExit() {
+ public void showExit() {
System.out.println(EXIT_MESSAGE);
}
- public static void showHelp() {
+ public void showHelp() {
System.out.println(HELP);
}
- public static void showLine() {
+ public void showLine() {
System.out.println(LINE);
}
- public static void showDudeMainError(Exception e) {
+ public void showDudeMainError(Exception e) {
if (e instanceof IOException) {
System.out.println(FILE_IO_ERROR + e);
} else {
System.out.println(DUDE_MAIN_ERROR + e);
}
}
- public static void showUnrecognizableErrorMessage() {
+ public void showUnrecognizableErrorMessage() {
System.out.println(UNRECOGNIZABLE_ERROR);
}
- public static void showUnrecognizableCommandErrorMessage() {
+ public void showUnrecognizableCommandErrorMessage() {
System.out.println(UNRECOGNIZABLE_COMMAND_ERROR);
}
- public static void showLoadingErrorMessage(Exception e) {
+ public void showLoadingErrorMessage(Exception e) {
if (e instanceof FileNotFoundException) {
System.out.println(FILE_NOT_FOUND_ERROR + e + CREATING_NEW_FILE_AND_DIRECTORY);
} else if (e instanceof FileParseReadingException) {
@@ -113,7 +96,7 @@ public static void showLoadingErrorMessage(Exception e) {
System.out.println(FILE_LOADING_DEFAULT_ERROR + e);
}
}
- public static void showAddingRecipeErrorMessage(Exception e) {
+ public void showAddingRecipeErrorMessage(Exception e) {
if (e instanceof IncompleteInputException) {
System.out.println(MISSING_DESCRIPTION_ERROR + e);
} else if (e instanceof StringIndexOutOfBoundsException) {
@@ -122,7 +105,7 @@ public static void showAddingRecipeErrorMessage(Exception e) {
System.out.println(RECIPE_ADDING_DEFAULT_ERROR + e);
}
}
- public static void showDeletingTaskErrorMessage(Exception e, CommandType type) {
+ public void showDeletingTaskErrorMessage(Exception e, CommandType type) {
if (e instanceof IncompleteInputException) {
System.out.println(MISSING_DESCRIPTION_ERROR + e);
} else if (e instanceof IndexOutOfBoundsException || e instanceof NullPointerException ||
@@ -132,7 +115,7 @@ public static void showDeletingTaskErrorMessage(Exception e, CommandType type) {
System.out.println(RECIPE_DELETING_DEFAULT_ERROR + e);
}
}
- public static void showFindingTaskErrorMessage(Exception e) {
+ public void showFindingTaskErrorMessage(Exception e) {
if (e instanceof IncompleteInputException) {
System.out.println(MISSING_INPUTS_ERROR + e);
} else {
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index 66b4188eed..cb595b92bc 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -4,7 +4,7 @@ Save file created.
__________________________________________________________
-HELLLOO there! I am
+HELLO there! I am
_____ _ _____ __ ___ ___ _ _______ ________ ____
|_ _| | | | _ |/ _| | \/ | ( ) / /_ _| _ | \/ \ \
| | __ _ ___| |_ ___ | | | | |_ | . . | ___ _ __ ___ |/ ___ | | | | | | | | . . || |
@@ -25,6 +25,107 @@ If you wish to view the full list of commands, simply type "help"!
__________________________________________________________
__________________________________________________________
+MATE! Your list is empty!
+
+__________________________________________________________
+__________________________________________________________
+
+Got it. I've added this recipe:
+ [Chinese] Hotpot
+Now you have 1 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+Got it. I've added this recipe:
+ [Chinese] MaLaXiangGuo
+Now you have 2 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+RECIPE LIST
+
+1. [Chinese] Hotpot
+2. [Chinese] MaLaXiangGuo
+
+__________________________________________________________
+__________________________________________________________
+
+Got it. I've added this recipe:
+ [Italian] Spaghetti
+Now you have 3 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+Got it. I've added this recipe:
+ [Italian] Carbonara
+Now you have 4 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+Got it. I've added this recipe:
+ [Chinese] Bejing Duck
+Now you have 5 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+RECIPE LIST
+
+1. [Chinese] Hotpot
+2. [Chinese] MaLaXiangGuo
+3. [Italian] Spaghetti
+4. [Italian] Carbonara
+5. [Chinese] Bejing Duck
+
+__________________________________________________________
+__________________________________________________________
+
+Noted. I've removed this recipe:
+ [Chinese] Hotpot
+Now you have 4 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+RECIPE LIST
+
+1. [Chinese] MaLaXiangGuo
+2. [Italian] Spaghetti
+3. [Italian] Carbonara
+4. [Chinese] Bejing Duck
+
+__________________________________________________________
+__________________________________________________________
+
+Noted. I've removed this recipe:
+ [Italian] Carbonara
+Now you have 3 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+RECIPE LIST
+
+1. [Chinese] MaLaXiangGuo
+2. [Italian] Spaghetti
+3. [Chinese] Bejing Duck
+
+__________________________________________________________
+__________________________________________________________
+
+All recipes have been cleared!
+__________________________________________________________
+__________________________________________________________
+
+MATE! Your list is empty!
+
+__________________________________________________________
+__________________________________________________________
+
Bye. Hope to see you again soon!
__________________________________________________________
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index a3abe50906..3cf40f6faf 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -1 +1,15 @@
+list
+add n/Hotpot i/Beef, Potatoes, Carrots t/Chinese
+add n/MaLaXiangGuo i/Beef, Mutton, Mushrooms t/Chinese
+list
+add n/Spaghetti i/Pasta, Tomato Sauce, Cheese t/Italian
+add n/Carbonara i/Pasta, Bacon, Egg, Cheese t/Italian
+add n/Bejing Duck i/Duck, Pancakes t/Chinese
+list
+delete 1
+list
+delete 3
+list
+clear
+list
exit
From 8cd2d0537ebb7d60dd4d25a67a92adf0e5f19781 Mon Sep 17 00:00:00 2001
From: liuziyang <3189362094@qq.com>
Date: Wed, 15 Mar 2023 15:48:11 +0800
Subject: [PATCH 3/6] no message
---
src/main/java/seedu/duke/command/Command.java | 12 +++++++
.../java/seedu/duke/recipe/Ingredient.java | 3 ++
.../seedu/duke/recipe/IngredientList.java | 6 ++++
src/main/java/seedu/duke/recipe/Recipe.java | 1 -
src/main/java/seedu/duke/ui/StringLib.java | 2 ++
src/main/java/seedu/duke/ui/UI.java | 18 ++++++++++
text-ui-test/EXPECTED.TXT | 33 +++++++++++++++++++
text-ui-test/input.txt | 4 +++
8 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/src/main/java/seedu/duke/command/Command.java b/src/main/java/seedu/duke/command/Command.java
index 800019b3e6..1110f89fb3 100644
--- a/src/main/java/seedu/duke/command/Command.java
+++ b/src/main/java/seedu/duke/command/Command.java
@@ -106,6 +106,18 @@ public void execute(RecipeList recipeList, UI ui) {
recipeList.clearRecipeList();
ui.showRecipeListCleared();
break;
+ case VIEW:
+ try {
+ if (fullDescription.isEmpty()) {
+ throw new IncompleteInputException("The index of " + type + " cannot be empty.\n");
+ }
+ recipeListIndex = Integer.parseInt(fullDescription);
+ Recipe recipeToBeViewed = recipeList.getRecipeFromList(recipeListIndex);
+ ui.showRecipeViewed(recipeToBeViewed);
+ } catch (Exception e) {
+ ui.showViewingRecipeErrorMessage(e);
+ }
+ break;
case HELP:
ui.showHelp();
break;
diff --git a/src/main/java/seedu/duke/recipe/Ingredient.java b/src/main/java/seedu/duke/recipe/Ingredient.java
index aee4e293c9..722cd03a3b 100644
--- a/src/main/java/seedu/duke/recipe/Ingredient.java
+++ b/src/main/java/seedu/duke/recipe/Ingredient.java
@@ -6,4 +6,7 @@ public class Ingredient {
public Ingredient(String inputName) {
name = inputName;
}
+ public String getName() {
+ return name;
+ }
}
diff --git a/src/main/java/seedu/duke/recipe/IngredientList.java b/src/main/java/seedu/duke/recipe/IngredientList.java
index ff025ca434..e696dcaef1 100644
--- a/src/main/java/seedu/duke/recipe/IngredientList.java
+++ b/src/main/java/seedu/duke/recipe/IngredientList.java
@@ -49,4 +49,10 @@ private void removeIngredient(int index) {
list.remove(index-1);
currIngredientNumber--;
}
+ public void showList() {
+ System.out.println("Here are " + currIngredientNumber + " ingredients in the list:");
+ for (int i = 0; i < currIngredientNumber; i++) {
+ System.out.println((i + 1) + ". " + list.get(i).getName());
+ }
+ }
}
diff --git a/src/main/java/seedu/duke/recipe/Recipe.java b/src/main/java/seedu/duke/recipe/Recipe.java
index b020922d72..842e7d1e06 100644
--- a/src/main/java/seedu/duke/recipe/Recipe.java
+++ b/src/main/java/seedu/duke/recipe/Recipe.java
@@ -30,7 +30,6 @@ public String getName() {
public String getTag() {
return tag;
}
-
public String toString() {
return '[' + tag + "] " + name;
}
diff --git a/src/main/java/seedu/duke/ui/StringLib.java b/src/main/java/seedu/duke/ui/StringLib.java
index fb6387769f..feb1fd523e 100644
--- a/src/main/java/seedu/duke/ui/StringLib.java
+++ b/src/main/java/seedu/duke/ui/StringLib.java
@@ -83,6 +83,8 @@ public interface StringLib {
+ "\nException occurred: ";
String RECIPE_FINDING_DEFAULT_ERROR = "\nError in finding recipe!"
+ "\nException occurred: ";
+ String RECIPE_VIEWING_DEFAULT_ERROR = "\nError in viewing recipe!"
+ + "\nException occurred: ";
String FORMAT_CONVERT_ERROR = "\nError in inputs!"
+ "\nException occurred: The number is too big to process or the inputs contains words when "
+ "it is supposed to be numbers."
diff --git a/src/main/java/seedu/duke/ui/UI.java b/src/main/java/seedu/duke/ui/UI.java
index a985c0203d..947f116b5e 100644
--- a/src/main/java/seedu/duke/ui/UI.java
+++ b/src/main/java/seedu/duke/ui/UI.java
@@ -4,6 +4,7 @@
import seedu.duke.exceptions.FileParseReadingException;
import seedu.duke.exceptions.IncompleteInputException;
import seedu.duke.exceptions.RecipeListEmptyError;
+import seedu.duke.recipe.IngredientList;
import seedu.duke.recipe.Recipe;
import java.io.FileNotFoundException;
@@ -122,4 +123,21 @@ public void showFindingTaskErrorMessage(Exception e) {
System.out.println(RECIPE_FINDING_DEFAULT_ERROR + e);
}
}
+ public void showRecipeViewed(Recipe recipe) {
+ System.out.println("Here is the recipe you requested, which is a "+ recipe.getTag() + " flavour:");
+ System.out.println("name: " + recipe.getName());
+ IngredientList ingredients = recipe.getIngredientList();
+ ingredients.showList();
+// System.out.println("steps: " + recipe.getSteps());
+ }
+ public void showViewingRecipeErrorMessage(Exception e) {
+ if (e instanceof IncompleteInputException) {
+ System.out.println(MISSING_DESCRIPTION_ERROR + e);
+ } else if (e instanceof IndexOutOfBoundsException || e instanceof NullPointerException ||
+ e instanceof RecipeListEmptyError) {
+ System.out.println(PREFIX_EMPTY_LIMIT_LIST_ERROR + CommandType.VIEW + SUFFIX_EMPTY_LIMIT_LIST_ERROR);
+ } else {
+ System.out.println(RECIPE_VIEWING_DEFAULT_ERROR + e);
+ }
+ }
}
diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT
index cb595b92bc..c8f9d0338f 100644
--- a/text-ui-test/EXPECTED.TXT
+++ b/text-ui-test/EXPECTED.TXT
@@ -117,6 +117,39 @@ RECIPE LIST
__________________________________________________________
__________________________________________________________
+Got it. I've added this recipe:
+ [Chinese] XiaoLongBao
+Now you have 4 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+Got it. I've added this recipe:
+ [Chinese] Guilinggao
+Now you have 5 recipes in the list.
+
+__________________________________________________________
+__________________________________________________________
+
+RECIPE LIST
+
+1. [Chinese] MaLaXiangGuo
+2. [Italian] Spaghetti
+3. [Chinese] Bejing Duck
+4. [Chinese] XiaoLongBao
+5. [Chinese] Guilinggao
+
+__________________________________________________________
+__________________________________________________________
+Here is the recipe you requested, which is a Chinese flavour:
+name: MaLaXiangGuo
+Here are 3 ingredients in the list:
+1. Beef
+2. Mutton
+3. Mushrooms
+__________________________________________________________
+__________________________________________________________
+
All recipes have been cleared!
__________________________________________________________
__________________________________________________________
diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt
index 3cf40f6faf..d60939de28 100644
--- a/text-ui-test/input.txt
+++ b/text-ui-test/input.txt
@@ -10,6 +10,10 @@ delete 1
list
delete 3
list
+add n/XiaoLongBao i/Pork, Soup, Dumplings t/Chinese
+add n/Guilinggao i/Tea, Milk, Sugar t/Chinese
+list
+view 1
clear
list
exit
From ce645e0b6966c0625ea95657e4fd3302253af6b0 Mon Sep 17 00:00:00 2001
From: liuziyang <3189362094@qq.com>
Date: Wed, 15 Mar 2023 15:55:55 +0800
Subject: [PATCH 4/6] fixed: import error
---
src/main/java/seedu/duke/ui/UI.java | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/main/java/seedu/duke/ui/UI.java b/src/main/java/seedu/duke/ui/UI.java
index 947f116b5e..d7e1a4ddf2 100644
--- a/src/main/java/seedu/duke/ui/UI.java
+++ b/src/main/java/seedu/duke/ui/UI.java
@@ -12,8 +12,31 @@
import java.util.ArrayList;
import java.util.Scanner;
-import static seedu.duke.ui.StringLib.*;
-
+import static seedu.duke.ui.StringLib.CREATING_NEW_FILE_AND_DIRECTORY;
+import static seedu.duke.ui.StringLib.DUDE_MAIN_ERROR;
+import static seedu.duke.ui.StringLib.EMPTY_LIST_MESSAGE;
+import static seedu.duke.ui.StringLib.EXIT_MESSAGE;
+import static seedu.duke.ui.StringLib.FILE_IO_ERROR;
+import static seedu.duke.ui.StringLib.FILE_LOADING_DEFAULT_ERROR;
+import static seedu.duke.ui.StringLib.FILE_NOT_FOUND_ERROR;
+import static seedu.duke.ui.StringLib.FILE_PARSE_READING_ERROR;
+import static seedu.duke.ui.StringLib.FIND_LIST_MESSAGE;
+import static seedu.duke.ui.StringLib.HELP;
+import static seedu.duke.ui.StringLib.LINE;
+import static seedu.duke.ui.StringLib.MISSING_DESCRIPTION_ERROR;
+import static seedu.duke.ui.StringLib.MISSING_INPUTS_ERROR;
+import static seedu.duke.ui.StringLib.NO_MATCHING_FIND_RESULTS_MESSAGE;
+import static seedu.duke.ui.StringLib.PARSING_STRING_ERROR;
+import static seedu.duke.ui.StringLib.PREFIX_EMPTY_LIMIT_LIST_ERROR;
+import static seedu.duke.ui.StringLib.RECIPE_ADDING_DEFAULT_ERROR;
+import static seedu.duke.ui.StringLib.RECIPE_DELETING_DEFAULT_ERROR;
+import static seedu.duke.ui.StringLib.RECIPE_FINDING_DEFAULT_ERROR;
+import static seedu.duke.ui.StringLib.SUFFIX_EMPTY_LIMIT_LIST_ERROR;
+import static seedu.duke.ui.StringLib.UNRECOGNIZABLE_COMMAND_ERROR;
+import static seedu.duke.ui.StringLib.UNRECOGNIZABLE_ERROR;
+import static seedu.duke.ui.StringLib.WELCOME_MESSAGE;
+import static seedu.duke.ui.StringLib.RECIPE_CLEARED_MESSAGE;
+import static seedu.duke.ui.StringLib.RECIPE_VIEWING_DEFAULT_ERROR;
public class UI {
private static Scanner in;
From ca7606267bb0c749ea940bc9f4748e2e9ae9fc14 Mon Sep 17 00:00:00 2001
From: liuziyang <3189362094@qq.com>
Date: Wed, 15 Mar 2023 16:14:37 +0800
Subject: [PATCH 5/6] add a assert and a Junit test
---
.../java/seedu/duke/recipe/RecipeList.java | 1 +
src/test/java/seedu/duke/UITest.java | 41 +++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/src/main/java/seedu/duke/recipe/RecipeList.java b/src/main/java/seedu/duke/recipe/RecipeList.java
index f5074c8726..8dc12b41b9 100644
--- a/src/main/java/seedu/duke/recipe/RecipeList.java
+++ b/src/main/java/seedu/duke/recipe/RecipeList.java
@@ -23,6 +23,7 @@ public ArrayList getRecipeList() {
}
public int getCurrRecipeNumber() {
+ assert(currRecipeNumber == recipeList.size());
return currRecipeNumber;
}
diff --git a/src/test/java/seedu/duke/UITest.java b/src/test/java/seedu/duke/UITest.java
index ba94f73320..240fb457e9 100644
--- a/src/test/java/seedu/duke/UITest.java
+++ b/src/test/java/seedu/duke/UITest.java
@@ -3,11 +3,52 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.BeforeEach;
+import seedu.duke.parser.Parser;
+import seedu.duke.recipe.IngredientList;
+import seedu.duke.recipe.Recipe;
+import seedu.duke.recipe.RecipeList;
+import seedu.duke.ui.UI;
+import seedu.duke.command.CommandType;
+import java.util.ArrayList;
public class UITest {
+ UI ui;
+ RecipeList recipeList;
+ private final CommandType type = CommandType.DELETE;
@Test
void printGreeting() {
assertTrue(true);
}
+ @BeforeEach
+ void setUp() {
+ ui = new UI();
+ recipeList = new RecipeList();
+ try{
+ ArrayList parsed = Parser.parseRecipe(
+ "add n/Spaghetti i/Pasta, Tomato Sauce, Cheese t/Italian");
+ String recipeName = parsed.get(0);
+ IngredientList ingredientLists = Parser.parseIngredients(parsed.get(1));
+ String recipeTag = parsed.get(2);
+ ArrayList recipeSteps = new ArrayList<>();
+ Recipe recipe = new Recipe(recipeName, recipeTag, ingredientLists, recipeSteps);
+ recipeList.addNewRecipe(recipe);
+ } catch (Exception e) {
+ ui.showAddingRecipeErrorMessage(e);
+ }
+ }
+ @Test
+ void addRecipe() {
+ assert(recipeList.getCurrRecipeNumber() == 1);
+ }
+ @Test
+ void deleteRecipe() {
+ try {
+ recipeList.removeRecipe(1);
+ } catch (Exception e) {
+ ui.showDeletingTaskErrorMessage(e,type);
+ }
+ assert(recipeList.getCurrRecipeNumber() == 0);
+ }
}
From 9cb2a4c3456e0fe04ffa3d237480dbc897651162 Mon Sep 17 00:00:00 2001
From: liuziyang <3189362094@qq.com>
Date: Wed, 15 Mar 2023 16:16:44 +0800
Subject: [PATCH 6/6] Style check
---
src/main/java/seedu/duke/ui/UI.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/seedu/duke/ui/UI.java b/src/main/java/seedu/duke/ui/UI.java
index d7e1a4ddf2..9b64527d3e 100644
--- a/src/main/java/seedu/duke/ui/UI.java
+++ b/src/main/java/seedu/duke/ui/UI.java
@@ -151,7 +151,6 @@ public void showRecipeViewed(Recipe recipe) {
System.out.println("name: " + recipe.getName());
IngredientList ingredients = recipe.getIngredientList();
ingredients.showList();
-// System.out.println("steps: " + recipe.getSteps());
}
public void showViewingRecipeErrorMessage(Exception e) {
if (e instanceof IncompleteInputException) {