forked from nus-cs2103-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2021S1#76 from xinyee20/Participation_XY
v1.2b Add Participation Score
- Loading branch information
Showing
8 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/java/seedu/address/logic/commands/AddScoreCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StudentInfo> 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)); | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/seedu/address/logic/parser/AddScoreCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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<AddScoreCommand> { | ||
|
||
/** | ||
* 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> student; | ||
int score; | ||
|
||
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)); | ||
|
||
return new AddScoreCommand(student.get(), score); | ||
} else { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddScoreCommand.MESSAGE_USAGE)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/java/seedu/address/logic/commands/AddScoreCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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_addScoreOutOfRange_failure() { | ||
|
||
} | ||
|
||
@Test | ||
public void execute_addScore_success() { | ||
|
||
} | ||
|
||
} |