Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W5][M11-1]Hu Yidi #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected ReadOnlyPerson getTargetPerson() throws IndexOutOfBoundsException {
return relevantPersons.get(getTargetIndex() - DISPLAYED_INDEX_OFFSET);
}


public int getTargetIndex() {
return targetIndex;
}
Expand Down
30 changes: 30 additions & 0 deletions src/seedu/addressbook/commands/TotalCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.person.ReadOnlyPerson;

import java.util.List;


/**
* Lists all persons in the address book to the user.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect header comment. Remember to update the comment when you change the code (this looks like a copy-paste-forgot error)

*/
public class TotalCommand extends Command {

public static final String COMMAND_WORD = "total";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Total number of persons in the address book.\n"
+ "Example: " + COMMAND_WORD;


@Override
public CommandResult execute() {
List<ReadOnlyPerson> totalList = addressBook.getAllPersons().immutableListView();
int TOTALNUMBER = totalList.size();

return new CommandResult(TOTALNUMBER+" "+
"IS THE TOTAL NUMBER OF EXISTING CONTACTS");
}
}


4 changes: 4 additions & 0 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import seedu.addressbook.commands.HelpCommand;
import seedu.addressbook.commands.IncorrectCommand;
import seedu.addressbook.commands.ListCommand;
import seedu.addressbook.commands.TotalCommand;
import seedu.addressbook.commands.ViewAllCommand;
import seedu.addressbook.commands.ViewCommand;
import seedu.addressbook.data.exception.IllegalValueException;
Expand Down Expand Up @@ -88,6 +89,9 @@ public Command parseCommand(String userInput) {
case ListCommand.COMMAND_WORD:
return new ListCommand();

case TotalCommand.COMMAND_WORD:
return new TotalCommand();

case ViewCommand.COMMAND_WORD:
return prepareView(arguments);

Expand Down