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][T08-01]-ZhaoJunRu #44

Open
wants to merge 2 commits 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
3 changes: 3 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ Views all details of the 1st person in the results of the `find` command.

== Clearing all entries : `clear`

Warning message for clearing all data
Key in "YES" to continue
Clears all entries from the address book. +
Any key to exit clear function
Copy link

Choose a reason for hiding this comment

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

Good that you have updated the UserGuide

Format: `clear`

== Exiting the program : `exit`
Expand Down
16 changes: 13 additions & 3 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package seedu.addressbook.commands;
import java.util.*;

/**
* Clears the address book.
Expand All @@ -8,12 +9,21 @@ public class ClearCommand extends Command {
public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_USAGE = "Clears address book permanently.\n"
+ "Example: " + COMMAND_WORD;

public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_FAILURE = "Exiting clear function";


@Override
public CommandResult execute() {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
System.out.println("Confirm to clear the entire address book? YES to continue");
Copy link

Choose a reason for hiding this comment

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

Simple but a useful change!

Scanner scanner = new Scanner(System.in);
String next = scanner.next();
if (next.equals("YES")) {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
}

return new CommandResult(MESSAGE_FAILURE);
}
}