From 1fb550bf0abe1709689318dea2ae33a1c3bfb80f Mon Sep 17 00:00:00 2001
From: yyutong <1037662939@qq.com>
Date: Wed, 14 Oct 2020 18:01:11 +0800
Subject: [PATCH] Add viewCategory command
---
src/main/java/seedu/address/ExpenseMainApp.java | 3 ++-
.../logic/commands/DeleteDescriptionCommand.java | 10 ++++++----
.../logic/commands/ViewCategoryCommand.java | 16 +++++-----------
3 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/src/main/java/seedu/address/ExpenseMainApp.java b/src/main/java/seedu/address/ExpenseMainApp.java
index eeb6f8e3623..51d8e0100ad 100644
--- a/src/main/java/seedu/address/ExpenseMainApp.java
+++ b/src/main/java/seedu/address/ExpenseMainApp.java
@@ -69,7 +69,8 @@ public void init() throws Exception {
}
/**
- * Returns a {@code ExpenseModelManager} with the data from {@code storage}'s expense book and {@code userPrefs}.
+ * Returns a {@code ExpenseModelManager} with the data from {@code storage}'s expense book
+ * and {@code userPrefs}.
* The data from the sample expense book will be used instead if {@code storage}'s expense book is not found,
* or an empty expense book will be used instead if errors occur when reading {@code storage}'s expense book.
*/
diff --git a/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java b/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java
index e7bd6386fa6..e7aa4ee04dc 100644
--- a/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java
+++ b/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java
@@ -8,8 +8,9 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
-import seedu.address.model.person.Expense;
import seedu.address.model.person.Description;
+import seedu.address.model.person.Expense;
+
/**
@@ -30,8 +31,8 @@ public class DeleteDescriptionCommand extends Command {
public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Description: %2$s";
public static final String MESSAGE_ADD_DESCRIPTION_SUCCESS = "Added description to Expense: %1$s \n";
public static final String MESSAGE_DELETE_DESCRIPTION_SUCCESS = "Removed description from Expense: %1$s \n";
- private final Index index;
private static final Description EMPTY_DESCRIPTION = new Description("");
+ private final Index index;
/**
* @param index of the expense in the filtered expense list to edit the description
@@ -51,7 +52,8 @@ public CommandResult execute(Model model) throws CommandException {
}
Expense expenseToEdit = lastShownList.get(index.getZeroBased());
- Expense editedExpense = new Expense(expenseToEdit.getAmount(), expenseToEdit.getDate(), expenseToEdit.getCategory(),
+ Expense editedExpense = new Expense(expenseToEdit.getAmount(), expenseToEdit.getDate(),
+ expenseToEdit.getCategory(),
EMPTY_DESCRIPTION);
model.setExpense(expenseToEdit, editedExpense);
@@ -85,4 +87,4 @@ private String generateSuccessMessage(Expense expenseToEdit) {
String message = MESSAGE_DELETE_DESCRIPTION_SUCCESS;
return String.format(message, expenseToEdit);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java b/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java
index 9d3a9e6ea72..45de39452b9 100644
--- a/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java
+++ b/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java
@@ -1,25 +1,19 @@
package seedu.address.logic.commands;
-import seedu.address.commons.core.Messages;
-import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
-import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.person.Category;
-import seedu.address.model.person.Description;
import seedu.address.model.person.Expense;
+import java.util.ArrayList;
import java.util.List;
-import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
-import static seedu.address.model.Model.PREDICATE_SHOW_ALL_EXPENSES;
-
public class ViewCategoryCommand extends Command {
public static final String COMMAND_WORD = "viewCategory";
public static final String MESSAGE_USAGE = COMMAND_WORD
- + ": Finds all the category labels used in the ExpenseBokk so far. \n"
+ + ": Finds all the category labels used in the ExpenseBook so far. \n"
+ "Example: " + COMMAND_WORD ;
public static final String MESSAGE_VIEW_CATEGORY_LABELS_SUCCESS =
@@ -30,10 +24,10 @@ public ViewCategoryCommand() {
@Override
public CommandResult execute(Model model) throws CommandException {
- List categories = model.getCategoryLabels();
String message = "";
- for(int i = 0; i < categories.size()-1; i++){
- message = message + categories.get(i).toString() + "\n";
+ List categories = model.getCategoryLabels();
+ for (int i = 0; i < categories.size(); i++){
+ message = message + categories.get(i).categoryName + "\n";
}
return new CommandResult(MESSAGE_VIEW_CATEGORY_LABELS_SUCCESS + message);
}