From e57cacf06f7e3a225e0938286f6d2fdddf8da000 Mon Sep 17 00:00:00 2001 From: xinyee20 Date: Tue, 6 Oct 2020 22:11:16 +0800 Subject: [PATCH 1/4] Fix ViewLsnCommand.java --- src/main/java/seedu/address/logic/commands/ViewLsnCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java b/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java index c6540ecad56..136bcc875b1 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLsnCommand.java @@ -46,6 +46,7 @@ private String getMessage(Model model) { @Override public CommandResult execute(Model model) { requireNonNull(model); + model.updateFilteredGroupList(grpPredicate); model.updateFilteredLessonList(lsnPredicate); return new CommandResult(this.getMessage(model)); } From a94240ffb9a45635ad943a533f5637973071bb1c Mon Sep 17 00:00:00 2001 From: xinyee20 Date: Mon, 12 Oct 2020 14:32:47 +0800 Subject: [PATCH 2/4] Add participation score command --- .../logic/commands/AddScoreCommand.java | 62 +++++++++++++++++++ .../logic/parser/AddScoreCommandParser.java | 45 ++++++++++++++ .../address/logic/parser/SerenityParser.java | 4 ++ .../logic/parser/SerenityParserUtil.java | 19 ++++++ .../address/model/group/Participation.java | 14 +++++ .../address/model/group/StudentInfo.java | 10 +++ .../logic/commands/AddScoreCommandTest.java | 19 ++++++ 7 files changed, 173 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/AddScoreCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java create mode 100644 src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java diff --git a/src/main/java/seedu/address/logic/commands/AddScoreCommand.java b/src/main/java/seedu/address/logic/commands/AddScoreCommand.java new file mode 100644 index 00000000000..bc46468b1fe --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/AddScoreCommand.java @@ -0,0 +1,62 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ID; +import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT; + +import javafx.collections.ObservableList; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.group.Lesson; +import seedu.address.model.group.Participation; +import seedu.address.model.group.Student; +import seedu.address.model.group.StudentInfo; +import seedu.address.model.group.UniqueStudentInfoList; + +public class AddScoreCommand extends Command { + + public static final String COMMAND_WORD = "addscore"; + public static final String MESSAGE_SUCCESS = "%s: \nParticipation Score - %d"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Gives a student in the class a participation score. \n" + + "Parameters: " + " " + "SCORE " + + PREFIX_STUDENT + " NAME" + " " + PREFIX_ID + " STUDENT_NUMBER\n" + + "Example: " + COMMAND_WORD + " " + "2" + " " + + PREFIX_STUDENT + " Aaron Tan" + " " + PREFIX_ID + " e0123456"; + + private Student toAddScore; + private int score; + + /** + * Creates an AddScoreCommand to award the specified {@code Student} a participation score + */ + public AddScoreCommand(Student student, int score) { + requireNonNull(student); + // Specified student to add participation score + toAddScore = student; + this.score = score; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + + Lesson uniqueLesson = model.getFilteredLessonList().get(0); + UniqueStudentInfoList uniqueStudentInfoList = uniqueLesson.getStudentsInfo(); + ObservableList studentsInfo = uniqueStudentInfoList.asUnmodifiableObservableList(); + + // Update single student participation score + for (int i = 0; i < studentsInfo.size(); i++) { + StudentInfo studentInfo = studentsInfo.get(i); + boolean isCorrectStudent = studentInfo.containsStudent(toAddScore); + if (isCorrectStudent) { + Participation update = studentInfo.getParticipation().setScore(score); + StudentInfo updatedStudentInfo = studentInfo.updateParticipation(update); + uniqueStudentInfoList.setStudentInfo(studentInfo, updatedStudentInfo); + } + } + return new CommandResult(String.format(MESSAGE_SUCCESS, toAddScore, score)); + + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java b/src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java new file mode 100644 index 00000000000..77301138631 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java @@ -0,0 +1,45 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ID; +import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENT; + +import java.util.Optional; + +import seedu.address.logic.commands.AddScoreCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.group.Student; + +public class AddScoreCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AddScoreCommand and + * returns a AddScoreCommand object for execution. + * + * @throws ParseException if the user input does not conform the expected format + */ + @Override + public AddScoreCommand parse(String userInput) throws ParseException { + ArgumentMultimap argMultimap = + ArgumentTokenizer + .tokenize(userInput, PREFIX_STUDENT, PREFIX_ID); + + String studentName; + String studentNumber; + Optional student; + int score; + + if (argMultimap.getValue(PREFIX_STUDENT).isPresent() && argMultimap.getValue(PREFIX_ID).isPresent()) { + + score = SerenityParserUtil.parseScore(argMultimap.getPreamble()); + studentName = SerenityParserUtil.parseStudent(argMultimap.getValue(PREFIX_STUDENT).get()); + studentNumber = SerenityParserUtil.parseStudentID(argMultimap.getValue(PREFIX_ID).get()); + student = Optional.ofNullable(new Student(studentName, studentNumber)); + + return new AddScoreCommand(student.get(), score); + } else { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddScoreCommand.MESSAGE_USAGE)); + } + } +} diff --git a/src/main/java/seedu/address/logic/parser/SerenityParser.java b/src/main/java/seedu/address/logic/parser/SerenityParser.java index 224942429f8..236ff290838 100644 --- a/src/main/java/seedu/address/logic/parser/SerenityParser.java +++ b/src/main/java/seedu/address/logic/parser/SerenityParser.java @@ -8,6 +8,7 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.AddGrpCommand; +import seedu.address.logic.commands.AddScoreCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.DeleteCommand; @@ -64,6 +65,9 @@ public Command parseCommand(String userInput) throws ParseException { case MarkAttCommand.COMMAND_WORD: return new MarkAttCommandParser().parse(arguments); + case AddScoreCommand.COMMAND_WORD: + return new AddScoreCommandParser().parse(arguments); + case UnmarkAttCommand.COMMAND_WORD: return new UnmarkAttCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/SerenityParserUtil.java b/src/main/java/seedu/address/logic/parser/SerenityParserUtil.java index 755c0e25b7d..47050daadea 100644 --- a/src/main/java/seedu/address/logic/parser/SerenityParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/SerenityParserUtil.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.group.Participation; import seedu.address.model.group.Student; public class SerenityParserUtil { @@ -34,4 +35,22 @@ public static String parseStudentID(String id) throws ParseException { } return trimmedId; } + + /** + * Parses {@code String} into an {@code int} and returns it. Leading and trailing whitespaces will be + * trimmed. + * + * @throws ParseException if the specified score is invalid. + */ + public static int parseScore(String inputScore) throws ParseException { + String trimmedScore = inputScore.trim(); + int score; + try { + score = Integer.parseInt(trimmedScore); + return score; + } catch (Exception e) { + throw new ParseException(Participation.SCORE_ERROR); + } + } + } diff --git a/src/main/java/seedu/address/model/group/Participation.java b/src/main/java/seedu/address/model/group/Participation.java index 7fa90f0e024..cad46b7398e 100644 --- a/src/main/java/seedu/address/model/group/Participation.java +++ b/src/main/java/seedu/address/model/group/Participation.java @@ -2,12 +2,21 @@ public class Participation { + public static final String SCORE_ERROR = "Score must be a number"; private final int score; public Participation() { this.score = 0; } + /** + * Creates a Participation object containing the score of a student + * @param score Score of Student + */ + public Participation(int score) { + this.score = score; + } + @Override public String toString() { return Integer.toString(score); @@ -17,6 +26,11 @@ public int getScore() { return score; } + public Participation setScore(int score) { + Participation updatedScore = new Participation(score); + return updatedScore; + } + @Override public boolean equals(Object obj) { Participation other = (Participation) obj; diff --git a/src/main/java/seedu/address/model/group/StudentInfo.java b/src/main/java/seedu/address/model/group/StudentInfo.java index 310c079ac40..245591ca404 100644 --- a/src/main/java/seedu/address/model/group/StudentInfo.java +++ b/src/main/java/seedu/address/model/group/StudentInfo.java @@ -68,6 +68,16 @@ public StudentInfo updateAttendance(Attendance updatedAttendance) { return updatedStudentInfo; } + /** + * Updates the student participation score for the class + * @param updatedScore The participation score of the student for the lesson + * @return The updated Participation object + */ + public StudentInfo updateParticipation(Participation updatedScore) { + StudentInfo updatedStudentInfo = new StudentInfo(this.student, updatedScore, this.attendance); + return updatedStudentInfo; + } + @Override public boolean equals(Object obj) { StudentInfo other = (StudentInfo) obj; diff --git a/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java b/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java new file mode 100644 index 00000000000..d5083712707 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java @@ -0,0 +1,19 @@ +package seedu.address.logic.commands; + +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +class AddScoreCommandTest { + + @Test + public void constructor_nullGroup_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new AddScoreCommand(null, 2)); + } + + @Test + public void execute_addScore_success() { + + } + +} From ae329e348ef5e5493e2a803631641f520c690e25 Mon Sep 17 00:00:00 2001 From: xinyee20 Date: Mon, 12 Oct 2020 17:30:37 +0800 Subject: [PATCH 3/4] Update score only accept number between 0 to 5 --- .../seedu/address/logic/parser/AddScoreCommandParser.java | 3 +++ src/main/java/seedu/address/model/group/Group.java | 7 +++---- .../seedu/address/logic/commands/AddScoreCommandTest.java | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java b/src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java index 77301138631..5b26f5820fd 100644 --- a/src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java @@ -32,6 +32,9 @@ public AddScoreCommand parse(String userInput) throws ParseException { if (argMultimap.getValue(PREFIX_STUDENT).isPresent() && argMultimap.getValue(PREFIX_ID).isPresent()) { score = SerenityParserUtil.parseScore(argMultimap.getPreamble()); + if (score < 0 || score > 5) { + throw new ParseException("Score should be between 0 to 5"); + } studentName = SerenityParserUtil.parseStudent(argMultimap.getValue(PREFIX_STUDENT).get()); studentNumber = SerenityParserUtil.parseStudentID(argMultimap.getValue(PREFIX_ID).get()); student = Optional.ofNullable(new Student(studentName, studentNumber)); diff --git a/src/main/java/seedu/address/model/group/Group.java b/src/main/java/seedu/address/model/group/Group.java index 3be2454c926..3d766ad4883 100644 --- a/src/main/java/seedu/address/model/group/Group.java +++ b/src/main/java/seedu/address/model/group/Group.java @@ -63,12 +63,11 @@ public Group(String name, UniqueStudentList students) { * @param students A list of students. * @param lessons A list of tutorial classes. */ - - public Group(String name, UniqueStudentList students, UniqueLessonList classes) { - requireAllNonNull(name, students, classes); + public Group(String name, UniqueStudentList students, UniqueLessonList lessons) { + requireAllNonNull(name, students, lessons); this.name = name; this.students = students; - this.lessons = lessons; + this.lessons = this.lessons; } public String getName() { diff --git a/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java b/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java index d5083712707..0f58f3cdbc3 100644 --- a/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java @@ -11,6 +11,11 @@ public void constructor_nullGroup_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new AddScoreCommand(null, 2)); } + @Test + public void execute_addScoreOutOfRange_Failure() { + + } + @Test public void execute_addScore_success() { From 3e3781c339d372721de23edb0648e4ab75319c2d Mon Sep 17 00:00:00 2001 From: xinyee20 Date: Mon, 12 Oct 2020 17:34:39 +0800 Subject: [PATCH 4/4] fix checkstyle --- .../java/seedu/address/logic/commands/AddScoreCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java b/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java index 0f58f3cdbc3..d2e42c7183c 100644 --- a/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java @@ -12,7 +12,7 @@ public void constructor_nullGroup_throwsNullPointerException() { } @Test - public void execute_addScoreOutOfRange_Failure() { + public void execute_addScoreOutOfRange_failure() { }