forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix bug when max scores were negative, and feedback given #111
Merged
lm-44
merged 3 commits into
AY2425S1-CS2103-F11-1:master
from
lm-44:Fix-HelpfulFeedback
Oct 28, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,24 +30,24 @@ public AddAssignmentCommand parse(String args) throws ParseException { | |
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddAssignmentCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_STUDENT_INDEX, PREFIX_ASSIGNMENT_NAME, | ||
PREFIX_ASSIGNMENT_MAX_SCORE); | ||
|
||
Index studentIndex; | ||
AssignmentName assignmentName; | ||
int maxScore; | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_STUDENT_INDEX, PREFIX_ASSIGNMENT_NAME, | ||
PREFIX_ASSIGNMENT_MAX_SCORE); | ||
try { | ||
studentIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_STUDENT_INDEX).get()); | ||
assignmentName = ParserUtil.parseAssignmentName(argMultimap.getValue(PREFIX_ASSIGNMENT_NAME).get()); | ||
maxScore = ParserUtil.parseMaxScore(argMultimap.getValue(PREFIX_ASSIGNMENT_MAX_SCORE).get()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
AddAssignmentCommand.MESSAGE_USAGE), pe); | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddAssignmentCommand.MESSAGE_USAGE), pe); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good formatting to follow coding standard |
||
} | ||
|
||
AddAssignmentCommand.AssignmentDescriptor assignmentDescriptor = | ||
new AddAssignmentCommand.AssignmentDescriptor(maxScore, assignmentName); | ||
|
||
return new AddAssignmentCommand(studentIndex, assignmentDescriptor); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.StringUtil; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.assignment.Assignment; | ||
import seedu.address.model.assignment.AssignmentName; | ||
import seedu.address.model.student.Email; | ||
import seedu.address.model.student.Name; | ||
|
@@ -118,13 +119,10 @@ | |
public static int parseMaxScore(String maxScore) throws ParseException { | ||
requireNonNull(maxScore); | ||
String trimmedMaxScore = maxScore.trim(); | ||
int parsedScore; | ||
try { | ||
parsedScore = Integer.parseInt(trimmedMaxScore); | ||
} catch (NumberFormatException e) { | ||
throw new ParseException("The score must be an integer!"); | ||
if (!StringUtil.isUnsignedInteger(trimmedMaxScore)) { | ||
throw new ParseException(Assignment.MAX_SCORE_MESSAGE_CONSTRAINTS); | ||
} | ||
return parsedScore; | ||
return Integer.parseInt(trimmedMaxScore); | ||
Comment on lines
-121
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a similar issue happening in gradeAssignmentCommand. Great attempt to simplify the code. |
||
} | ||
/** | ||
* Parses a {@code String score} into a {@code int}. | ||
|
@@ -135,30 +133,23 @@ | |
public static int parseScore(String score) throws ParseException { | ||
requireNonNull(score); | ||
String trimmedScore = score.trim(); | ||
int parsedScore; | ||
try { | ||
parsedScore = Integer.parseInt(trimmedScore); | ||
} catch (NumberFormatException e) { | ||
if (!StringUtil.isUnsignedInteger(trimmedScore)) { | ||
throw new ParseException("The score must be an integer!"); | ||
} | ||
return parsedScore; | ||
return Integer.parseInt(trimmedScore); | ||
} | ||
/** | ||
* Parses a {@code String studentIndex} into a {@code int}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code studentIndex} is invalid. | ||
*/ | ||
public static int parseStudentIndex(String studentIndex) throws ParseException { | ||
requireNonNull(studentIndex); | ||
String trimmedStudentIndex = studentIndex.trim(); | ||
int parsedStudentIndex; | ||
try { | ||
parsedStudentIndex = Integer.parseInt(trimmedStudentIndex); | ||
} catch (NumberFormatException e) { | ||
throw new ParseException("The score must be an integer!"); | ||
public static int parseStudentIndex(String oneBasedIndex) throws ParseException { | ||
String trimmedIndex = oneBasedIndex.trim(); | ||
if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) { | ||
throw new ParseException(MESSAGE_INVALID_INDEX); | ||
} | ||
return parsedStudentIndex; | ||
return Integer.parseInt(trimmedIndex); | ||
} | ||
/** | ||
* Parses {@code Collection<String> tags} into a {@code Set<Tag>}. | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on ensuring the input is a valid unsigned integer and not a signed one.