Skip to content

Commit 4d2e956

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#82 from yyutong/view-expense-command
View expense command
2 parents ba8e3e2 + 8dcf4a4 commit 4d2e956

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

src/main/java/seedu/address/logic/commands/ViewCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ViewCommand extends Command {
2020
+ "Parameters: INDEX (must be a positive integer)\n"
2121
+ "Example: " + COMMAND_WORD + " 1";
2222

23-
public static final String MESSAGE_VIEW_EXPENSE_SUCCESS = "View Expense: %1$s";
23+
public static final String MESSAGE_VIEW_EXPENSE_SUCCESS = "View Expense: %s";
2424

2525
private final Index targetIndex;
2626

@@ -37,9 +37,9 @@ public CommandResult execute(Model model) throws CommandException {
3737
}
3838

3939
Expense expenseToView = lastShownList.get(targetIndex.getZeroBased());
40-
String message = targetIndex.toString() + "\n" + expenseToView.toString();
41-
// model.viewExpense(targetIndex);
42-
return new CommandResult(String.format(MESSAGE_VIEW_EXPENSE_SUCCESS, message));
40+
String prefix = String.format(MESSAGE_VIEW_EXPENSE_SUCCESS, targetIndex.getZeroBased());
41+
String message = prefix + "\n" + expenseToView.toString();
42+
return new CommandResult(message);
4343
}
4444

4545
@Override

src/main/java/seedu/address/model/ExpenseModelManager.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,6 @@ public void setExpense(Expense target, Expense editedExpense) {
120120
expenseBook.setExpense(target, editedExpense);
121121
}
122122

123-
/**
124-
* View the detals of a certain expense.
125-
*
126-
* @param index The index of the expense to be viewed in the ExpenseBook.
127-
*/
128-
@Override
129-
public void viewExpense(Index index) {
130-
expenseBook.viewExpense(index);
131-
}
132123

133124
//=========== Filtered Expense List Accessors =============================================================
134125

src/main/java/seedu/address/model/person/Expense.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,26 @@ public String toString() {
8989
if (description.isEmpty()) {
9090
builder.append(" Amount: ")
9191
.append(this.getAmount())
92+
.append("\n")
9293
.append(" Date: ")
9394
.append(this.getDate())
95+
.append("\n")
9496
.append(" Category: ")
95-
.append(this.getCategory());
97+
.append(this.getCategory())
98+
.append("\n");
9699
return builder.toString();
97100
} else {
98101
builder.append(" Amount: ")
99102
.append(this.getAmount())
100-
.append("/n")
103+
.append("\n")
101104
.append(" Date: ")
102105
.append(this.getDate())
103106
.append(" Category: ")
104-
.append("/n")
105107
.append(this.getCategory())
108+
.append("\n")
106109
.append(" Description: ")
107110
.append(this.getDescription())
108-
.append("/n");
111+
.append("\n");
109112
return builder.toString();
110113
}
111114
}

0 commit comments

Comments
 (0)