Skip to content

Commit

Permalink
now if the user inputs a name that does not exist, an exception is th…
Browse files Browse the repository at this point in the history
…rown and specifies which names are incorrect.
  • Loading branch information
Niu BoQian committed Mar 24, 2023
1 parent 0d172a3 commit a6d18f1
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ docs/_site/
*.fxml
*.class
*.css
*.png
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Messages {
+ "Lesson name: %s\n"
+ "Start Time: %s\n"
+ "End Time: %s\n";
public static final String MESSAGE_HAS_DUPLICATE_NAMES = "Duplicate names detected for **%s** "
+ "please enter full name(s)";
public static final String MESSAGE_HAS_DUPLICATE_NAMES = "Duplicate names detected for **%s**."
+ "\nPlease enter full name(s)";
public static final String MESSAGE_NO_SUCH_STUDENT = "No student found: **%s**.\nPlease check the name entered";
}
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/commands/CreateExamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public CreateExamCommand(List<String> names, NamePredicate predicate, String exa
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public CreateLessonCommand(List<String> names, NamePredicate predicate, String l
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteExamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public DeleteExamCommand(List<String> inputNames, NamePredicate predicate, Index
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : inputNames) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder("");
for (String name : inputNames) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public DeleteLessonCommand(List<String> inputNames, NamePredicate predicate, Ind
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : inputNames) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder("");
for (String name : inputNames) {
if (model.hasDuplicateName(name)) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/commands/UpdateExamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public UpdateExamCommand(List<String> names, Index index, NamePredicate predicat
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public UpdateLessonCommand(List<String> names, Index index, NamePredicate predic
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/commands/ViewExamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public ViewExamCommand(List<String> names, Predicate<Student> namePredicate, Pre
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/commands/ViewLessonCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public ViewLessonCommand(List<String> names, Predicate<Student> namePredicate,
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public CreateHomeworkCommand(List<String> names, NamePredicate predicate, String
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}

StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public DeleteHomeworkCommand(List<String> names, NamePredicate predicate, Index
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public MarkHomeworkAsDoneCommand(List<String> names, NamePredicate predicate, In
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public MarkHomeworkAsUndoCommand(List<String> names, NamePredicate predicate, In
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public UpdateHomeworkCommand(List<String> names, Index index, NamePredicate pred
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ public ViewHomeworkCommand(List<String> names, Predicate<Student> namePredicate,
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
StringBuilder nonExistNames = new StringBuilder();
for (String name : names) {
if (model.noSuchStudent(name)) {
nonExistNames.append(name).append(", ");
}
if (nonExistNames.length() != 0) {
nonExistNames = new StringBuilder(nonExistNames.substring(0, nonExistNames.length() - 2));
throw new CommandException(String.format(Messages.MESSAGE_NO_SUCH_STUDENT, nonExistNames));
}
}
StringBuilder dupNames = new StringBuilder();
for (String name : names) {
if (model.hasDuplicateName(name)) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ public interface Model {
void updateFilteredStudentList(Predicate<Student> predicate);

boolean hasDuplicateName(String name);

boolean noSuchStudent(String name);
}
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,14 @@ public boolean hasDuplicateName(String name) {
}
return count >= 2;
}

@Override
public boolean noSuchStudent(String name) {
for (Student s : filteredPersons) {
if (s.getName().toString().contains(name)) {
return false;
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ public void updateFilteredStudentList(Predicate<Student> predicate) {
public boolean hasDuplicateName(String name) {
throw new AssertionError("this method should not be called.");
}

@Override
public boolean noSuchStudent(String name) {
throw new AssertionError("this method should not be called.");
}
}

/**
Expand Down

0 comments on commit a6d18f1

Please sign in to comment.